Is there any way to know from where the C++ exception originates ?

Bogdan Vacaliuc bvacaliuc at
Tue Sep 21 22:27:27 UTC 2004

Hello Valery, Angelo:

The topic of 'finding the line of code' that causes an exception has been interesting to me over the course of time.  So I got a wee
bit carried away with my response on this one, but I hope you will humor me.

Ultimately, some form of 'stack backtrace' is implemented to find the address of the instruction that caused the original exception
(usually a hardware trap, etc.).  This is also true for (structured) exception handling (software detected faults) in much the same

Unfortunately, there is little standards-mandated support for such items as the code is inherently non-portable.  The Java language
has built-into its exception system the concept of a stack backtrace which is available in the exception handler to great
popularity.  The same functionality is not widely available in C/C++ implementations.

This does not mean that it is not possible to obtain, it just means that you have to implement something specific for the
arch/platform/compiler that you are using.


Below are some links I saved while making a cursory survey of the topic.

A good start is here:

An interesting treatise on Java exceptions is here:

For the entire google search:
Google: +stack +trace +exception +"c++"

A recent discussion on GCC regarding stack trace generation (vis-a-vis gcj) is here:

An interesting (although anecdotal) chapter in the GNAT docs:

Here is a discussion on comp.std.c++ in Feb'03.  I tie-in at a point that illustrates some of the reasons why the standards
committes *avoid* putting this functionality in:

Finally, one of the more enlightened posts I have seen on this topic is:
(actually the whole thread is pretty good reading)

Hope this helps,


On Tuesday, September 21, 2004 3:53 PM, Angelo Fraietta wrote:

> Is this a history question or where in the code the exception occurs?
> Valery Pykhtin wrote:
>> Hi All,
>> may be this is an unappropriate place to ask, but may be someone
>> knows the answer in the topic ? 
>> Best regards,
>> Valery

More information about the users mailing list