*Experts* Bucky Posted March 12, 2003 *Experts* Posted March 12, 2003 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 Quote "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 quwiltw Posted March 13, 2003 Leaders Posted March 13, 2003 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? Quote --tim
*Experts* Bucky Posted March 13, 2003 Author *Experts* Posted March 13, 2003 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 :) Quote "Being grown up isn't half as fun as growing up These are the best days of our lives" -The Ataris, In This Diary
*Gurus* divil Posted March 13, 2003 *Gurus* Posted March 13, 2003 Your question has given me the neat idea of calling all my exceptions "up" just so I can Throw Up in my code :) Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.