Question: I want to have stack trace not for my exceptions only but also for any descendants of `std::exception`

As I understand, stack trace is completely lost when exception is caught because of stack unwinding (unrolling). 

So the only way I see to grab it is injection of code saving context info (stack trace) at the place of `std::exception` constructor call. Am I right?

If it is the case, please tell me how code injection can be done (if it can) in C++. Your method may be not completely safe because I need it for Debug version of my app only. May be I need to use assembler?

I'm interested only in solution for GCC. It can use c++0x features

Answer: 
On Linux this can be implemented by adding a call to [`backtrace()`](http://www.kernel.org/doc/man-pages/online/pages/man3/backtrace.3.html) in the exception constructor to capture the stack trace into an exception's member variable. Unfortunately, it won't work for standard exceptions, only for the ones you define.
Some years ago I wrote this: [Unchaining chained exceptions in C++](http://drdobbs.com/cpp/191100567)

Basically some macros log the place where the stack unwind happens when an exception is thrown.

An updated version of the framework can be found in the library Imebra (<http://imebra.com>).

I would reimplement some parts of it (like storing the stack trace on a thread local storage).