Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / November 2007

Tip: Looking for answers? Try searching our database.

Handling native cross-thread exceptions

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Zhenya - 20 Nov 2007 16:49 GMT
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?

If #1 is not possible, is there a catch-all exception handler at the process
level in C++?

Thank you very much for your help,

Evgueni
Carl Daniel [VC++ MVP] - 20 Nov 2007 17:05 GMT
> Hello,
>
[quoted text clipped - 5 lines]
> 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
Ben Voigt [C++ MVP] - 30 Nov 2007 19:30 GMT
>> Hello,
>>
[quoted text clipped - 8 lines]
> Overtly, no, it's not possibble.  Exceptions always propagate and are
> caught (or not) on the thread where the exception was raised.

Of course one option is to catch it on the same thread and pass a message
(PostMessage) to the main thread.

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.