catching Win32 API exceptions in C++ 
Author Message
 catching Win32 API exceptions in C++

Hello,

The documentation of InitializeCriticalSection tells me the following:
"In low memory situations, InitializeCriticalSection can raise a
STATUS_NO_MEMORY exception."
I'm writing in VC++ a class that wraps the CriticalSection API. How can I
catch such an exception with C++ exception handling ?

This issue led me to the general question: How do I catch exceptions raised
by the WIN32 API in C++ ?

Thanks,
Gadi Admoni.
SW Engineer, Radcom LTD.
http://www.*-*-*.com/ , http://www.*-*-*.com/ .



Mon, 08 Apr 2002 03:00:00 GMT  
 catching Win32 API exceptions in C++
Gadi,

Quote:

> The documentation of InitializeCriticalSection tells me the following:
> "In low memory situations, InitializeCriticalSection can raise a
> STATUS_NO_MEMORY exception."
> I'm writing in VC++ a class that wraps the CriticalSection API. How can I
> catch such an exception with C++ exception handling ?

> This issue led me to the general question: How do I catch exceptions
raised
> by the WIN32 API in C++ ?

The way to do this is to use _set_se_translator() to install your own
callback function that will get called when a SEH exception is raised,
allowing you to throw a C++ exception from there. This allows you to easily
translate Win32 exception codes into a C++ exception class with all the info
you need.

Take care about one thing: _set_se_translator should be called for _each_
thread you start.

--
Tomas Restrepo

http://members.xoom.com/trestrep/



Mon, 08 Apr 2002 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Catching Win32 exceptions with a C++ catch-block

2. Howto catch Win32 exceptions in C++?

3. Catching hardware exceptions using C++ exceptions

4. Catching SEC Exceptions as C++ Exceptions

5. Win32 structured exceptions vs C++ exceptions

6. Catching Win32/MFC Exceptions in eVC++

7. catching math exceptions with C++

8. Catching SEH and c++ exception

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

10. Catching Structure Exceptions in C++ EH

11. Q: Why try catch cannot catch the exception

12. C++ std library vs Win32 API

 

 
Powered by phpBB® Forum Software