Article View: comp.os.ms-windows.programmer.win32
Article #2073Re: MSVC++ 2.2 exception handling
From: Mike Granby
Date: Tue, 17 Oct 1995 09:43
Date: Tue, 17 Oct 1995 09:43
73 lines
2028 bytes
2028 bytes
In an earlier article Michael Falcon-Gates wrote:
> Oh, boy! (I love this one.) There are two completely separate
> exception handling mechanisms going on here. If you use the C++
> "catch" keyword, the only way you can catch operating-system
> exception is to use catch (...), and you can get no information
> about the exception.
Not true. Look up _set_se_translator in the VC reference manual. This
function can be used to install a filter which catches SEH exceptions
and translates them to C++ exceptions. It works pretty well - see the
code below for a trivial example of it in use.
===============
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <eh.h>
class CSystemException {
public:
CSystemException(UINT uCode)
{
m_uCode = uCode;
}
CSystemException(CSystemException const &Src)
{
m_uCode = Src.m_uCode;
}
UINT GetCode(void) const
{
return m_uCode;
}
protected:
UINT m_uCode;
};
void ExceptionTranslator(UINT uCode, EXCEPTION_POINTERS *pInfo)
{
throw CSystemException(uCode);
}
void main(void)
{
_set_se_translator(ExceptionTranslator);
try {
int *pData = NULL;
pData[0] = 1;
}
catch(CSystemException const &Ex) {
UINT uCode = Ex.GetCode();
printf("Caught code %X\n", uCode);
}
exit(0);
}
===============
--
Mike Granby
Paradigm Controls Limited
Technical Details
Message-ID:
<813923030.19043@paracon.demon.co.uk>Path:
arc1-ca.pugleaf.net!dispatch.news.demon.net!demon!paracon.demon.co.ukReferences:
<45k7j5$9rh@cnn.exu.ericsson.se> <1995Oct13.155228.5193@debet> <45u1ta$8ot@cnn.exu.ericsson.se> <45vmbp$8kf@kaleka.seanet.com>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!dispatch.news.demon.net!demon!paracon.demon.co.uk From: mikeg@paracon.co.uk (Mike Granby) Newsgroups: comp.os.ms-windows.programmer.win32,comp.lang.c++ Subject: Re: MSVC++ 2.2 exception handling Date: Tue, 17 Oct 1995 09:43:20 GMT Organization: Paradigm Controls Limited Message-ID: <813923030.19043@paracon.demon.co.uk> References: <45k7j5$9rh@cnn.exu.ericsson.se> <1995Oct13.155228.5193@debet> <45u1ta$8ot@cnn.exu.ericsson.se> <45vmbp$8kf@kaleka.seanet.com> NNTP-Posting-Host: paracon.demon.co.uk X-NNTP-Posting-Host: paracon.demon.co.uk X-Newsreader: Forte Agent .99b.112