473,385 Members | 1,341 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Catching exceptions from threads

In my multi-threaded application, a Win32 structured exception is
occasionally thrown from a worker thread. Or perhaps a worker thread might
throw a C++ exception. I can catch the Win32 structured exception in my
Main thread and take remedial action. However the C++ exception appears to
be handle by something (the CRT ?) which (a) pops up an unwanted dialog box
and (b) terminates my thread without my main thread ever getting to hear
about it.

I assume the CRT (or whatever) is deciding that I have an unhandled C++
exception and is "helping me out". Can I persuade the CRT somehow that I
want my main thread to catch a C++ exception which has been thrown in a
worker thread?

Obviously I can wrap each worker thread in a C++ try/catch block, but I'd
rather a more generic solution if one is available.

Many thanks
Nov 16 '05 #1
5 2406
When you get the msg box it probably has Break/Retry/Abort? Break and find
the cause

"Ron James" <Ro*******@nowhere.nospam.com> wrote in message
news:en****************@TK2MSFTNGP09.phx.gbl...
In my multi-threaded application, a Win32 structured exception is
occasionally thrown from a worker thread. Or perhaps a worker thread might throw a C++ exception. I can catch the Win32 structured exception in my
Main thread and take remedial action. However the C++ exception appears to be handle by something (the CRT ?) which (a) pops up an unwanted dialog box and (b) terminates my thread without my main thread ever getting to hear
about it.

I assume the CRT (or whatever) is deciding that I have an unhandled C++
exception and is "helping me out". Can I persuade the CRT somehow that I
want my main thread to catch a C++ exception which has been thrown in a
worker thread?

Obviously I can wrap each worker thread in a C++ try/catch block, but I'd
rather a more generic solution if one is available.

Many thanks

Nov 16 '05 #2
Unfortunately, it's not quite that simple. This is an application that can
process thousands of transactions per minute, and I get exceptions a few
times a week.
"Pent" <pent> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
When you get the msg box it probably has Break/Retry/Abort? Break and find
the cause

"Ron James" <Ro*******@nowhere.nospam.com> wrote in message
news:en****************@TK2MSFTNGP09.phx.gbl...
In my multi-threaded application, a Win32 structured exception is
occasionally thrown from a worker thread. Or perhaps a worker thread

might
throw a C++ exception. I can catch the Win32 structured exception in my Main thread and take remedial action. However the C++ exception appears

to
be handle by something (the CRT ?) which (a) pops up an unwanted dialog

box
and (b) terminates my thread without my main thread ever getting to hear
about it.

I assume the CRT (or whatever) is deciding that I have an unhandled C++
exception and is "helping me out". Can I persuade the CRT somehow that I want my main thread to catch a C++ exception which has been thrown in a
worker thread?

Obviously I can wrap each worker thread in a C++ try/catch block, but I'd rather a more generic solution if one is available.

Many thanks


Nov 16 '05 #3
Ron James wrote:
Obviously I can wrap each worker thread in a C++ try/catch block, but
I'd rather a more generic solution if one is available.


That's the correct solution. There's no way to catch an exception raised in
"Thread B" from within "Thread A".

-cd
Nov 16 '05 #4
Ron James <Ro*******@nowhere.nospam.com> wrote in message
news:en**************@TK2MSFTNGP09.phx.gbl...
Obviously I can wrap each worker thread in a C++ try/catch block, but I'd
rather a more generic solution if one is available.


As Carl has already mentioned, C++ exception handlers are with respect to a
stack frame and thread.

However, if you target XP or 2K+3, and if your problem is due to a
structured exception (i.e. from Win32) then you can preempt the structured
execption handler by installing a vectored execption handler.

You might want to take a look at this article by Matt Pietrek:

http://msdn.microsoft.com/msdnmag/is...d/default.aspx

and the MSDN help entry for AddVectoredExceptionHandler().

I should point out, though, that I haven't ever tried to mix C++ exceptions
and vectored exception handling as mixing the frame based exceptions is
enough to cause me a headache. :-)

Regards,
Will
Nov 16 '05 #5
The C runtime library is responsible for displaying that
alert box. It can be configured to write to stdout rather
than displaying an alert by:

_set_error_mode(_OUT_TO_STDERR);
-Bill Kirtley
kirtley at envoyww.com
-----Original Message-----
In my multi-threaded application, a Win32 structured exception isoccasionally thrown from a worker thread. Or perhaps a worker thread mightthrow a C++ exception. I can catch the Win32 structured exception in myMain thread and take remedial action. However the C++ exception appears tobe handle by something (the CRT ?) which (a) pops up an unwanted dialog boxand (b) terminates my thread without my main thread ever getting to hearabout it.

I assume the CRT (or whatever) is deciding that I have an unhandled C++exception and is "helping me out". Can I persuade the CRT somehow that Iwant my main thread to catch a C++ exception which has been thrown in aworker thread?

Obviously I can wrap each worker thread in a C++ try/catch block, but I'drather a more generic solution if one is available.

Many thanks
.

Nov 16 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Rolf | last post by:
I understand a compilation error occurs when a method that throws no exceptions is the only code in a try block. What I don't understnad is why I can specify the catching of an Exception for a...
2
by: Keith Bolton | last post by:
I am handling exceptions currently using try, except. Generally I don't handle specific exceptions and am catching all. Then if an exception occurs, I would like to capture that error string....
7
by: cmay | last post by:
FxCop complains every time I catch System.Exception. I don't see the value in trying to catch every possible exception type (or even figuring out what exceptions can be caught) by a given block...
12
by: Vasco Lohrenscheit | last post by:
Hi, I have a Problem with unmanaged exception. In the debug build it works fine to catch unmanaged c++ exceptions from other dlls with //managed code: try { //the form loads unmanaged dlls...
13
by: Chris Stankevitz | last post by:
Hi, I have a very large Visual c++ .net 2003 7.1 native c application (approximately 500,000 lines of code). This application is a simulation that frequently works with floating point numbers....
2
by: Alex | last post by:
Hi Is it possible to catch exceptions thrown by a System.Threading.Thread object? i.e. I have an instance of a class that is created using the normal Thread/ThreadStart method, but once it...
3
by: Mike Binks | last post by:
I wish to make sure all unhandled exceptions (UE) are handled by a central handler. For primary thread UEs, this may be done by string exceptionText; ...
5
by: Simon Tamman | last post by:
I have an object named DisasterRecovery. The Ctor of this object is this: private DisasterRecovery() { Application.ThreadException+= new...
1
by: BLUE | last post by:
I'm using CF 1.x (VS 2003) on a Windows CE 4.2 device. This classes ad methods are not present: Application.ThreadException ThreadExceptionEventHandler Application.SetUnhandledExceptionMode...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.