Daniel, it's a bit difficult to paste my code as it's pretty long.
The principal is the same as my example.
(classes 2 and 3 are my custom classes)
My first class is my Form.
My form calls a static method in Class2 (synchronization class)
Class2 calls a static method of Class3 (sockets class)
If an error occurs in class 3 then i want a messagebox to show what the
error is, at the moment the error stops and errors on the line:
throw new Exception (ex.message); in class2, it needs to bubble up to
class1 (my form class) so i can display a message.
I think that makes sense.
Thanks for the help.
PS. Please look at my other weird problem while you're about
Daniel Moth said:
I'll have to insist. Show us the code!
To answer your new question, yes they are different.
If all you are doing is
catch{
throw; //maps to a rethrow IL statement
}
you might as well not catch the exception and let it bubble up. If you
want
to do something before "throw;" then that is fine but consider whether a
finally would be a better choice.
If you want to create a new exception, then do so but make sure the
innerException points to the original so the stacktrace is not completely
lost.
Cheers
Daniel
--
http://www.danielmoth.com/Blog/
Rob S said:
Thanks for the responses.
Does throw; behave differently from throw new Exception(ex.Message);
??
I was under the impression they both do exactly the same thing?
:
FYI, if you want to bubble the same exception up, just call throw
try
{
....
}
catch(Exception)
{
throw;
}
[C#]
I have three classes
The first class calls a method on the second class, from the second
class
a
method from the third class is called.
If an error is caught in the third class i simply bubble it back to
the
calling function, like so: throw new Exception (ex.Message);
However from the second class i can't then do another throw new
Exception...
back to the first class. It just generates a runtime error.
Any ideas why?