Exception reporting/Logging

R

Raj

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");
}
 
J

Jorgen Grahn

Hi
I am using the follwoing calls to report/log the exceptions of
functions.

I see no exceptions below -- I assume you mean "... the execution 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");
}

Yes, it's clumpsy. Why Memo1->Lines->Append(x) when you could just say
memo.apppend(x) -- or even better, memo << x ?

I also do not understand the SaveToFile(path) call; if you are writing
to file, it's easier, faster and safer to do it directly.

What is also missing is formatting of data. Sooner or later you will
want to print something other than string constants: integers,
pointers, user-defined objects ... I have seen code where half the
content of the functions deal with a mix of stringstreams, toString()
calls and sprintf():ing temporary char arrays just for the debug
messages -- that is ugly!

I suggest using a normal std::eek:stream instead of Memo1. There are ways
to add timestamps, to add file/line/function information, to disable
printing, or to disable it completely at runtime.

Finally: why do you need so much logging? You can step through the
code in a debugger, and/or write unit tests. When you have done that,
you will probably find that you didn't need the logging.

/Jorgen
 
G

Guest

Finally: why do you need so much logging?  You can step through the
code in a debugger,
yuk
[instead]

[...] write unit tests.
yes!

When you have done that,
you will probably find that you didn't need the logging.

and when it does something strange in the field?
Aeroplanes fly with black boxes for a reason
 
J

Jorgen Grahn

....


and when it does something strange in the field?
Aeroplanes fly with black boxes for a reason

I never said that no programs need any logging, did I?

I was talking specifically about the poster and his example; I got the
impression he wanted very extensive trace messages for trivial code.

/Jorgen
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,164
Messages
2,570,898
Members
47,439
Latest member
shasuze

Latest Threads

Top