Exception Handling in a Class or Worker Thread (.NET 2.0)

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi

What is the correct (or best) way to handle (catch) exceptions in a class or
in a worker thread in .NET 2.0?
In my project, I've a class which do some cryptographic operations. This
class runs also in a seperate thread (not main thread). Now, how should I
handle the possible exceptions in this class?

Thanks and Regards,
Dominik
 
Hi Vadym

Thank you for your answer.

Now my next questions:
I use the try{} catch{} block in my class. Also, I catch the
CryptographicException. When a exception occurs in my class, should I throw a
new exception within the catch block? Should I raise a custom event? Or
should I write the exception message in a public property so that I can use
the message in the main thread?

I would like to know which is the best way (the Microsoft recommend way) to
handle exceptions and work with this exceptions.


Thanks and Regards,
Dominik
 
Hi Vadym
It depends on what you want to do with that exception. If you want to show it to
user then you can display it in the GUI using Control.Invoke technique (
multithreading under winforms ).

That means that I have to raise my custom event (when I would like to use
the Control.Invoke method)?

Regards,
Dominik
 
Hello, Zemp!

ZD> That means that I have to raise my custom event (when I would like to
ZD> use the Control.Invoke method)?

Custom event will execute only if there are subscribers on it ( handlers ). And this
handler(s) will Control.Invoke. Or you can directly use Control.Invoke without custom event.

--
Regards, Vadym Stetsyak
www: http://vadmyst.blogspot.com
 
Hi Vadym

You wrote: Or you can directly use Control.Invoke without custom event.

How can I do this? Do you have an example?

Regards,
Dominik
 
Back
Top