
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/