Discussion:
Error reporting/Logging - Help
(too old to reply)
Raj
2009-01-29 18:06:48 UTC
Permalink
Hi
I am using the follwoing calls to report/log the exceptions of
functions. This works ok. But when the code grows, this makes the code
a lot clumsy. Can you please suggest some ways of smart reporting
using builder.
Thanks
Raj
if(FunctionReturns == Error)
{
Memo1->Lines->Append("instanceTest->LoadInputImageFile()");
Memo1->Lines->Append( A2iARC_GetLastError ( ));
Memo1->Lines->SaveToFile("C:\\Test_Project.txt");
}
else
{
Memo1->Lines->Append("instanceTest->LoadInputImageFile()");
Memo1->Lines->Append("OK");
Memo1->Lines->SaveToFile("C:\\Test_Project.txt");
}
m***@gmail.com
2009-01-30 18:18:51 UTC
Permalink
Not sure about the smartest way,
but I can tell my humble opinion.

1) Using an object to encapsulate logging operations
would slim down the code considerably:
if (FunctionReturns==Error) Log->Error(A2iARC_GetLastError());
else Log->Success("Ok");
Your Log class could be a TMemo descendant.

2) Consider to avoid logging successful
operations, 'Ok' is usually a redundant information
(absence of errors may suffice)
In this case 'real' Exceptions can be very handy,
consider this:

Application->OnException = OnExceptionHandler;
...
//---------------------------------------------------------------------------
void __fastcall TmyForm::OnExceptionHandler(TObject *Sender, Exception
*E)
{
//Application->ShowException(E);
Memo1->Lines->Append("instanceTest->LoadInputImageFile()");
Memo1->Lines->Append( E->Message );
//if ( Application->Terminated ) // Crash log
Memo1->Lines->SaveToFile("C:\\Test_Project.txt");
}
...
if (FunctionReturns == Error) throw Exception( A2iARC_GetLastError
() );
Raj
2009-02-02 10:53:14 UTC
Permalink
Post by m***@gmail.com
Not sure about the smartest way,
but I can tell my humble opinion.
1) Using an object to encapsulate logging operations
if (FunctionReturns==Error) Log->Error(A2iARC_GetLastError());
else Log->Success("Ok");
Your Log class could be a TMemo descendant.
2) Consider to avoid logging successful
operations, 'Ok' is usually a redundant information
(absence of errors may suffice)
In this case 'real' Exceptions can be very handy,
Application->OnException = OnExceptionHandler;
...
//---------------------------------------------------------------------------
void __fastcall TmyForm::OnExceptionHandler(TObject *Sender, Exception
*E)
{
    //Application->ShowException(E);
    Memo1->Lines->Append("instanceTest->LoadInputImageFile()");
    Memo1->Lines->Append( E->Message );
    //if ( Application->Terminated ) // Crash log
    Memo1->Lines->SaveToFile("C:\\Test_Project.txt");}
...
if (FunctionReturns == Error) throw Exception( A2iARC_GetLastError
() );
Thank you. This is very useful

Loading...