retrieve exception context in C++ exception handler 
Author Message
 retrieve exception context in C++ exception handler

I'm writing an application using C++ style exceptions, (try/catch), and
within the handler, I would like to do a stack trace from the point where
the exception occurred. With SEH exceptions (__try/__except) this was no
problem using the _exception_info() function in the filter. However, with
C++ exceptions I have found no way of doing this. Can anyone help me with
this?

Thanks in advance,

Camiel.



Tue, 27 Jan 2004 11:27:24 GMT  
 retrieve exception context in C++ exception handler

Quote:

>I'm writing an application using C++ style exceptions, (try/catch), and
>within the handler, I would like to do a stack trace from the point where
>the exception occurred. With SEH exceptions (__try/__except) this was no
>problem using the _exception_info() function in the filter. However, with
>C++ exceptions I have found no way of doing this. Can anyone help me with
>this?

Those stack frames are gone by the time you reach a C++ exception
handler, so there's nothing to trace back to.

--
Doug Harrison [VC++ MVP]
Eluent Software, LLC
http://www.eluent.com
Tools for Visual C++ and Windows



Tue, 27 Jan 2004 11:39:30 GMT  
 retrieve exception context in C++ exception handler
In that case, if I use __try/__except, can I determine the type (class) of
the C++ exception that was thrown and reference it?



Quote:

> >I'm writing an application using C++ style exceptions, (try/catch), and
> >within the handler, I would like to do a stack trace from the point where
> >the exception occurred. With SEH exceptions (__try/__except) this was no
> >problem using the _exception_info() function in the filter. However, with
> >C++ exceptions I have found no way of doing this. Can anyone help me with
> >this?

> Those stack frames are gone by the time you reach a C++ exception
> handler, so there's nothing to trace back to.

> --
> Doug Harrison [VC++ MVP]
> Eluent Software, LLC
> http://www.eluent.com
> Tools for Visual C++ and Windows



Tue, 27 Jan 2004 11:49:22 GMT  
 retrieve exception context in C++ exception handler

Quote:

>In that case, if I use __try/__except, can I determine the type (class) of
>the C++ exception that was thrown and reference it?

Since __try/__except don't deal with C++ exceptions, I would say no.

Have you looked at _set_se_translator? You might be able to copy the
low-level exception information associated with an SE into the C++
exception that you throw from your translator function. But that's
still not going to help with true C++ exceptions, which don't start
out as SEs.

--
Doug Harrison [VC++ MVP]
Eluent Software, LLC
http://www.eluent.com
Tools for Visual C++ and Windows



Wed, 28 Jan 2004 02:44:05 GMT  
 retrieve exception context in C++ exception handler
Yes, I'm using the _set_se_translator, that works fine. For now, I've
embedded the stack tracing into my exception class. When the exception
object is created, it traces the stack. I'll setup try/catch handlers
everywhere where other CException-based exceptions are thrown and embed them
inside an instance of my own exception class (with the stack trace)... a
pain, but... if it works, it will make runtime support a lot easier...



Quote:

> >In that case, if I use __try/__except, can I determine the type (class)
of
> >the C++ exception that was thrown and reference it?

> Since __try/__except don't deal with C++ exceptions, I would say no.

> Have you looked at _set_se_translator? You might be able to copy the
> low-level exception information associated with an SE into the C++
> exception that you throw from your translator function. But that's
> still not going to help with true C++ exceptions, which don't start
> out as SEs.

> --
> Doug Harrison [VC++ MVP]
> Eluent Software, LLC
> http://www.eluent.com
> Tools for Visual C++ and Windows



Wed, 28 Jan 2004 07:58:03 GMT  
 retrieve exception context in C++ exception handler

Quote:

>I'm writing an application using C++ style exceptions, (try/catch), and
>within the handler, I would like to do a stack trace from the point where
>the exception occurred. With SEH exceptions (__try/__except) this was no
>problem using the _exception_info() function in the filter. However, with
>C++ exceptions I have found no way of doing this. Can anyone help me with
>this?

>Thanks in advance,

>Camiel.

To get a stack trace at any point, I do something like this

class StackTrace_Exception;   // stores exception state

void temp_translator(unsigned int code, EXCEPTION_POINTERS *exp)
{
   throw StackTrace_Exception( exp );   // store the exception state

Quote:
}

// In the get callstack function

_set_se_translator(temp_translator);

try
{
   RaiseException(0,0,0,0);   // cause the translator to be called

Quote:
}

catch( StackTrace_Exception &e )
{
   // do stack trace here with exception state from e

Quote:
}

// restore old translator

The only thing to beware is not to set another translator
inside the a translating funtion.



Fri, 30 Jan 2004 11:30:42 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. C4530: C++ exception handler used, but unwind semantics are

2. Underflow exception handler for Borland C++?

3. Translate a SEH exception into a C++ exception

4. Catching hardware exceptions using C++ exceptions

5. Catching SEC Exceptions as C++ Exceptions

6. Win32 structured exceptions vs C++ exceptions

7. Exceptions : Combining C++ and Structured Exception Handling ?

8. multiple event handlers exception help

9. exception handler

10. Redirect Exception Handler?

11. Exception Handler for StrCpy

12. How do I code an exception handler?

 

 
Powered by phpBB® Forum Software