verbose exception
- From: Thomas Metz <tmetz free fr>
- To: gtkmm-list gnome org
- Subject: verbose exception
- Date: Fri, 22 Sep 2006 22:07:15 +0200
Hi,
I have written a small class, called verbose_exception. The goal is to be able
to know where an exception occurs through tracing the functions stack between
the "throw" and the final "catch" (a verbose error message with the stack
trace is built).
I'd like to know what do you think about this kind of feature and if it would
be interresting to add something simular in glibmm.
Example of error message :
---------------------------------------
Unable to read myFile.bin 2 : bad_format
while executing "int test_ex ()" (file test_verbose_exception.cpp line 42)
in "int test_ex ()" (file test_verbose_exception.cpp catch line 48)
in "void test ()" (file test_verbose_exception.cpp catch line 58)
in "int main ()" (file test_verbose_exception.cpp catch line 95)
---------------------------------------
=> first line : error message + user message
=> second line : file, line and function where the exception is thrown
=> other lines : functions stack
The code linked to the example :
int test_ex()
{
try {
int fileId = 2;
char * fileName = "myFile.bin";
VE_THROW_VERBOSE_EXCEPTION(bad_format,
"Unable to read " << fileName << " "
<< fileId << " : " << VE_WHAT);
return 0;
}
VE_CATCH_RETHROW()
}
void test()
{
try {
test_ex();
}
VE_CATCH_RETHROW()
}
int main()
{
try {
cout << " *** User exception (from user code) ***" << endl;
test();
}
VE_CATCH_PRINT()
return 0;
}
Inconvenients :
- a VE_CATCH_RETHROW macro shall be added on all methods / functions
- lots of use of macro
Advantage :
- friendly error message for developper and for user (really easier to debug)
- easy way to send lots of information in an exception
- easy way to add user exceptions.
Note that some level (library) can be disabled to limit the stack.
To get the experimental class :
http://tmetz.free.fr/verbose_exception-0.4-1.tgz
Regards,
Thomas Metz
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]