Zhenya wrote:
Hello,
I am a C++ newbie. I developed a Win32 DLL that creates a number of
threads, which can throw exceptions. When an exception is thrown on a
thread in Win32 DLL, I want to catch that exception on the main
thread.
Is there any way to throw an exception on one thread and catch it on
another thread?
Overtly, no, it's not possibble. Exceptions always propagate and are caught
(or not) on the thread where the exception was raised.
If #1 is not possible, is there a catch-all exception handler at the
process level in C++?
The effect of an unhandled exception is to terminate the process. You can
change that behavior by using the Win32 function
SetUnhandledExceptionFilter. Generally, you shouldn't do anything other
than possibly inform the user that the program must terminate and then
terminate the process yourself. If you want to produce a crash dump, this
is best handled by associating a custom debugger (or Dr Watson) with your
executable and having that debugger produce the crash dump. Such a debugger
runs as a separate process launched when your main program crashes, so you
don't have to worry about the state of the stack, heap, or code image of the
crashed process - it can be completely trashed and the debugger can still
produce a crash dump - something that you cannot be guaranteed of doing from
inside the crashed process itself.
-cd