Retaining exception source information

paolopaolo Member paolo volpiOrganization: tvblobProject: tvblob blobbox
What about implementing something like :

In C++, whenever an exception is caught within a handler, the information about the source of the exception is lost. The exact source of the exception could provide a lot of vital information to better handle it, or the information could be appended to the error log for postmortem.

To deal with this, you can generate a stack trace in the constructor of the exception object during the throw exception statement. ExceptionTracer is a class that demonstrates this behavior.

Listing 1. Generating a stack trace in the exception object constructor

// Sample Program:
// Compiler: gcc 3.2.3 20030502
// Linux: Red Hat

#include <execinfo.h>
#include <signal.h>

#include <exception>
#include <iostream>

using namespace std;


class ExceptionTracer
void * array[25];
int nSize = backtrace(array, 25);
char ** symbols = backtrace_symbols(array, nSize);

for (int i = 0; i < nSize; i++)
cout << symbols << endl;


adding a member variable to Ice::Exception that implements this idea?

I found this article on Ibm web site:
C++ exception-handling tricks for Linux
Sign In or Register to comment.