I want to save all the errors in the database. The problem occurs when an EOracleError error occurs, because then there is no information in the message about the error string or about the error.

To catch errors, I use the TApplicationEvents component:

procedure TfrmMain.ApplicationEvents1Exception(Sender: TObject; E: Exception); begin dmMain.oqLog.SetVariable(':V_ERROR', e.ToString); dmMain.oqLog.Execute; end; 

For the test, I cause an error no_data_found by executing the query:

 begin raise no_data_found; end; 

As a result, in e.ToString I have: ORA-01403: no data found ORA-06512: at line 2 . The string e.StackTrace is generally empty.

How to get the name of the dataset, the forms and lines in which the error occurred?

  • one
    Try madExcept. He can write logs with exceptions and more. - Kromster
  • And whether prompt it is possible to hide a window in madExcept with the message that there was an error? need to make it invisible to the user. - Alena Shlykova
  • Yes, of course you can. - Kromster

2 answers 2

I did a separate method to perform the TOracleDataSet request. Implementation, however, on CBuilder, but the difference is small. Line number in the request is not displayed.

 bool ExecuteSQL( TOracleQuery* Q ) //В качестве входного параметра может быть TOracleDataSet { AnsiString StringError = ""; TOracleSession* OS = Q->Session; TCheckConnectionResult Result; Q->Close(); try{ //Сначала проверяем связь с БД if ( OS ) Result = Q->Session->CheckConnection( true ); else { MesBoxErr("Не установлено соединение с базой данных"); return false; } } catch ( Exception & E ) { MesBoxErr( "Ошибка подключения к базе данных"); return false; } if ( Result == ccError ) { MesBoxErr( "Потеряно соединение с базой данных." ); return false; } //если связь с БД есть проверяем запрос try { Q->Execute() ; //Если TOracleDataSet, то Q->Open(); } catch ( Exception & E ) { StringError = "При выполнении запроса " + Q->Name + "\n"; StringError += Q->SQL + "\n"; MesBoxErr( ( StringError + "возникла ошибка:\n" + E.Message ).c_str() ); return false; } } return true; } 

    The concept of recording each error in the database in conditionally real time is incorrect. Such an implementation keeps the network connection in a constant “voltage”, which ultimately affects the performance of the application. In addition, if this is a spacer (that is, a database server somewhere far away on the Internet), then serious delays, queues, and other unpredictability are possible.

    In my applications, I implement logging first to a local file, and then, when the file reaches a certain number of lines, I do the logging to the database. Moreover, it makes this a separate stream, which temporarily pauses recording, spy log, and then creates a new one.

    The log can be kept in XML or in tab-delimited format.

    • This is a good commentary on the question, but unfortunately not the answer. - Kromster
    • On the one hand, this is not the answer to a specific question - right. But on the other ... Perhaps the advice will make you think about architecture. Yes, and arrange this advice in the form of a comment would be difficult. - Interface Unknown
    • A comment limit of 600 characters is enough. Moreover, the question "How to get the name of the dataset, the forms and lines in which the error occurred?", And the record in the database, in this case, is secondary. - Kromster