Article View: comp.os.ms-windows.programmer.win32
Article #2071Re: MSVC++ 2.2 exception handling
From: ROLAND KAUFMANN
Date: Mon, 16 Oct 1995 21:37
Date: Mon, 16 Oct 1995 21:37
49 lines
1868 bytes
1868 bytes
In article <45u1ta$8ot@cnn.exu.ericsson.se>, Paul Stephenson <paul.stephenson@ebu.ericsson.se> writes:
> siv_941268@debet.nhh.no (ROLAND KAUFMANN) wrote:
>>Any kind of exception is caught in this clause. It is the
>>exception-equivalent of the 'else' statement.
>
>
> Yes, I realize that. I'm asking a question about the behavior of the
> runtime system. It appears to throw an exception upon an access
> violation. If I know the type of that exception, I can write a separate
> handler to catch it rather than relying on the "catch any" handler.
You'll have to write a system exception handler that'll throw a C++
exception, and then test whether that exception is the exception you're
looking for.
#include <eh.h>
#include <windows.h>
#include <stdio.h>
class XAccessViolation { };
void _se_trans_func( unsigned int i, struct _EXCEPTION_POINTERS* )
{
if( i == EXCEPTION_ACCESS_VIOLATION )
{
XAccessViolation x;
throw x;
}
else
throw i; // just to make sure something's thrown!
}
void main( void )
{
_set_se_translator( &_se_trans_func );
try
{A
unsigned char *puch = 0;
*puch = '\n';
}
catch( XAccessViolation x )
{
printf( "An access violation occurred\n" );
}
catch( ... )
{
printf( "An unknown exception occurred\n" );
}
}
Technical Details
Message-ID:
<1995Oct16.223715.5210@debet>Path:
arc1-ca.pugleaf.net!nntp-trd.UNINETT.no!debet!siv_941268References:
<45k7j5$9rh@cnn.exu.ericsson.se> <1995Oct13.155228.5193@debet> <45u1ta$8ot@cnn.exu.ericsson.se>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!nntp-trd.UNINETT.no!debet!siv_941268 From: siv_941268@debet.nhh.no (ROLAND KAUFMANN) Newsgroups: comp.os.ms-windows.programmer.win32,comp.lang.c++ Subject: Re: MSVC++ 2.2 exception handling Message-ID: <1995Oct16.223715.5210@debet> Date: 16 Oct 95 22:37:15 MET References: <45k7j5$9rh@cnn.exu.ericsson.se> <1995Oct13.155228.5193@debet> <45u1ta$8ot@cnn.exu.ericsson.se> Organization: Norwegian School of Economics