Jump to content
Xtreme .Net Talk

Recommended Posts

  • *Experts*
Posted

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

"Being grown up isn't half as fun as growing up

These are the best days of our lives"

-The Ataris, In This Diary

  • Leaders
Posted

Perhaps I don't understand?

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?

--tim
  • *Experts*
Posted

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 :)

"Being grown up isn't half as fun as growing up

These are the best days of our lives"

-The Ataris, In This Diary

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...