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 2 1225
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******** ********@TK2MSF TNGP09.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
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************ *************@r eallyidont.com> wrote in
message news:d1******** ***********@new s.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). This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 decided to make my streambuf raise
exceptions upon device error states.
The code is supposed to run on several platforms, but there seems
to be some inconsistency between the different iostream
implementations. This led me to believe that I'm...
|
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 as the
following
try
{
Application.Run(new something());
}
catch
|
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 I have been
doing it right. I think I overdo it. Please have a look:
--
using System;
using System.IO;
|
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 method:
// --- Create an Exception Handler for Thread Exceptions ----------------
Application.ThreadException += new
ThreadExceptionEventHandler(OnThreadException);
|
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 when I run the executable from
within the .NET studio environment, thrown exceptions are caught and handled
correctly (both debug and release mode). However, if I run the executable
from outside the .NET studio, none of the exceptions get caught....
| |
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 gets about
3 or so. It also gets very awkward in nested loops, where you want to
check for normal loop processing in the loop condition, not errors.
Yes, you could put some generic exit flag in the loop condition, but
when you're simply done if...
|
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
exceptions.
Thanks,
|
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 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
|
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, especially as
programs get large.
Most of the issues of exceptions are not specific to Python, but I
sometimes feel that Python makes them more acute because of the free-n-
easy manner in which it employs exceptions for its own uses and allows
users...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |