Catching Win32 exceptions with a C++ catch-block 
Author Message
 Catching Win32 exceptions with a C++ catch-block

That's not possible. use either __try / __except (C exception handling) or
have a look to www.vcdj.com, there's an article showing how to specify your
own exception handler. So far this is the best method I've heard about,
because it doesn't require your statements to be included in blocks like
with try/catch.

You simply setup the handler at the beginning and replace by the old one
when you're done.

Olivier Gilloire

Quote:
>Is it possible to use only C++ try-catch blocks to handle both C++- and
>Win32 exceptions?

>The catch(...)-block catches the Win32-exceptions alright, but I need a way
>of determining what kind of Win32-exception has been thrown. Is this
>possible, or do I have to use a mix of try-catch and
>__try-__except-__finally?



Tue, 26 Sep 2000 03:00:00 GMT  
 Catching Win32 exceptions with a C++ catch-block

Yes, it's possible, and fairly easy.
See set_se_translator() in documentation; also knowledgebase Q167802.
I have implemented use of it and am about to enter testing.
I've used it in the past with success, though.
--

(remove the xxx from reply address)

Quote:

>Hello!

>Is it possible to use only C++ try-catch blocks to handle both C++- and
>Win32 exceptions?



Tue, 26 Sep 2000 03:00:00 GMT  
 Catching Win32 exceptions with a C++ catch-block

On Sat, 11 Apr 1998 14:06:12 +0200, "Jonas Kjellstrom"

Quote:

>Hello!

>Is it possible to use only C++ try-catch blocks to handle both C++- and
>Win32 exceptions?

>I would like to do something like this:

>try {
>    // Do things which may throw Win32- or C++-exceptions
>}
>catch( const CMyException& e )
>{
>    // Handle a C++ exception
>}
>catch(...)
>{
>    // Handle possible Win32 exception
>    DWORD dwE = GetExceptionCode();  // Does not work. Wrong context.
>}

>The catch(...)-block catches the Win32-exceptions alright,

In VC5, unless you're compiling with -EHa, that's a bug. catch(...)
under -EHs and the usual -GX should *not* catch SEs, but it does, most
of the time, anyway.

Quote:
>but I need a way
>of determining what kind of Win32-exception has been thrown. Is this
>possible, or do I have to use a mix of try-catch and
>__try-__except-__finally?

You can turn SEs into C++ exceptions with the help of
_set_se_translator. Then you can catch them specifically. You should
still compile with -EHa, however, because of the optimizations VC5
performs (e.g. if you compile with -O1 -GX, and it determines the code
inside the try block can't throw a C++ exception, then it will elide
the whole try/catch setup, leaving just the try block code, which is
good, unless you're expecting to catch things like *(char*) 0 = 0).

--
Doug Harrison



Tue, 26 Sep 2000 03:00:00 GMT  
 Catching Win32 exceptions with a C++ catch-block

Hello!

Is it possible to use only C++ try-catch blocks to handle both C++- and
Win32 exceptions?

I would like to do something like this:

try {
    // Do things which may throw Win32- or C++-exceptions

Quote:
}

catch( const CMyException& e )
{
    // Handle a C++ exception
Quote:
}

catch(...)
{
    // Handle possible Win32 exception
    DWORD dwE = GetExceptionCode();  // Does not work. Wrong context.

Quote:
}

The catch(...)-block catches the Win32-exceptions alright, but I need a way
of determining what kind of Win32-exception has been thrown. Is this
possible, or do I have to use a mix of try-catch and
__try-__except-__finally?

Thanks,

Jonas Kjellstrom
Connecta TN AB



Wed, 27 Sep 2000 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. catching Win32 API exceptions in C++

2. Howto catch Win32 exceptions in C++?

3. Q: Why try catch cannot catch the exception

4. Catching hardware exceptions using C++ exceptions

5. Catching SEC Exceptions as C++ Exceptions

6. Catching Win32/MFC Exceptions in eVC++

7. The if ~ else block in try~catch block

8. Why am I seeing such a delay between my catch block and my finally block

9. How to catch a SEH with C++ catch?

10. catching math exceptions with C++

11. Catching SEH and c++ exception

12. C++/MFC and exceptions- catch(...)=bad?

 

 
Powered by phpBB® Forum Software