Throw up

Bucky

Contributor
Joined
Dec 23, 2001
Messages
791
Location
East Coast
How do I throw an Exception in a method of a class and have it
travel upwards until it reaches an error handler? In other words,
I want the method to raise an error and the method's caller to
handle the error.

Currently I have the method call surrounded in a Try...Catch block,
but when I Throw the error in the method, the error occurs inside
the method itself.

If this isn't possible, should I just have an Error event and raise
the event when an error occurs?

Thanks
 
Perhaps I don't understand?
Visual Basic:
Public MySub()
  Try
      'do some processing that could throw an exception
  Catch ex As Exception
     Throw New Exception("Error in MySub",ex)
  End Try

End Sub
Is that what you're asking?
 
Ah, I hadn't thought about that, and that would work great for
the situation that I just described, I'm fairly sure.

But just now I realized that the description was incorrect... oops.

The sub that I'm throwing the error in is a sub that is called
asinchro-... asyncron-... asyncren-... uh, it's called async. :D
Anyway, it's a sub that's reading from a socket, so there's no
calling code of the sub to catch the exception.

I'll just set a protected string to the error description, and have
the main method that's called raise the error if the string contains
something.

Thanks Tim :)
 
Your question has given me the neat idea of calling all my exceptions "up" just so I can Throw Up in my code :)
 
Back
Top