473,382 Members | 1,563 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,382 software developers and data experts.

handling exceptions thrown from inside a thread

Bob
Is there some built-in way of handling exceptions thrown inside a thread, or
do I need to pass exception conditions to a delegate (which would force me
to handle all exceptions in the thread itself)?

TIA,
Bob
Nov 21 '05 #1
2 1204

Handle the exception in the usual way (Try/Catch). From there on in, it's
up to you what to do with it. Either yes, pass the error state back to the
client via. a delegate, or handle the error in the thread itself.
Personally, I use a delegate to tell the form what the error was and then
idle the thread (but ensuring no state was changed; in my case, by rolling
back a database transaction). The client form can then decide whether to
retry the operation (if it was cancelled due to deadlock for example) or
whether to just tell the user (a simple message box).

"Bob" <no***@nowhere.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Is there some built-in way of handling exceptions thrown inside a thread,
or
do I need to pass exception conditions to a delegate (which would force me
to handle all exceptions in the thread itself)?

TIA,
Bob

Nov 21 '05 #2
Bob
Good answer, thank you.

Maybe you can answer a few more threading questions for me?

- For cleanup, is it sufficient to set a Thread to Nothing after it's done?

- It is OK to pass objects out of the thread? (dumb question maybe but I
want to be sure)

- What's the best way to process messages coming out of a thread? I want to
queue them up, but MessageQueue doesn't look like what I need. Should I just
make my own queue class? If so I'll have to worry about enumerator
synchronization... a pointer to a 'best practice' example would be very
helpful.

Bob

"Robin Tucker" <id*************************@reallyidont.com> wrote in
message news:d1*******************@news.demon.co.uk...

Handle the exception in the usual way (Try/Catch). From there on in, it's
up to you what to do with it. Either yes, pass the error state back to the client via. a delegate, or handle the error in the thread itself.
Personally, I use a delegate to tell the form what the error was and then
idle the thread (but ensuring no state was changed; in my case, by rolling
back a database transaction). The client form can then decide whether to
retry the operation (if it was cancelled due to deadlock for example) or
whether to just tell the user (a simple message box).

Nov 21 '05 #3

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

Similar topics

0
by: Viktor Lundström | last post by:
Hi! I recently decided to write a streambuf which handles streamed IO to a device (ie. a socket). Now, in an effort to move away from C-style IO error handling (ie. if(read(..) == -1) ...), I...
3
by: Robert Rotstein | last post by:
It appears that exception handling at the top-most level of a C# program, in the static void Main() method, differs depending on whether the program is run in debug mode or not. That is, code such...
9
by: Gustaf | last post by:
I'm confused about structured error handling. The following piece of code is a simplification of a class library I'm working on. It works, and it does what I want, but I'm still not convinced that...
16
by: Chuck Cobb | last post by:
I'm implementing a centralized exception handling routine using the Enterprise Library Exception Management Application Block. I trap all unhandled exceptions to one place using the following...
6
by: Robin Riley | last post by:
Hi, I have a .NET solution that contains a dll project and a tester application project which, of course, invokes the dll. The dll project has exception handling in it. What's happening is that...
35
by: jeffc226 | last post by:
I'm interested in an idiom for handling errors in functions without using traditional nested ifs, because I think that can be very awkward and difficult to maintain, when the number of error checks...
7
by: =?Utf-8?B?THVib21pcg==?= | last post by:
Hi, Is it possible to set up C# compiler so that I would get a warning when I miss any exception thrown by a framework? Something like in Java, where the compiler forces you to handle all...
2
by: =?Utf-8?B?Wmhlbnlh?= | last post by:
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...
35
by: eliben | last post by:
Python provides a quite good and feature-complete exception handling mechanism for its programmers. This is good. But exceptions, like any complex construct, are difficult to use correctly,...
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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.