locked
Error Handling with VB.Net RRS feed

  • Question

  • Hello All,

    My question is very general.

    I was wondering what's the prefered way of using error handling?

    Let's say I have a button, a function and a class.  Do I want to put an error handler in each of these or would I just put in say the form that calling the function that in the class?  If I have an error handler in each of these that has a messagebox for example, wouldn't the message box fire off 3 times?

    What's everyones thought on this?

    Thanks.

    jcb

    Wednesday, January 24, 2007 5:32 PM

Answers

  • Hi

    That's a very general question and you'll no doubt get a different answer from everyone you speak to ... but for what it's worth.

    You only need to handle an exception if you know what to do with it.  If you don't, let it go up the stack in case earlier code does.

    If you get the to the end of the stack an don't handle the exception your application will terminate.  Depending on the nature of the application, this is a good thing or a bad thing.

    There is a global unhandled exception event in the application class of an executable that you could handle and do some last minute stuff in there before stopping your application/letting it continue if you want to.

    I personally like the checked/unchecked approach to exceptions that some languages enforce.  You may want to do some googling about that, or perhaps download FXCop and adopt it's recommendations for exception handling.  There's some good blog posts by it's developer on this very issue (sorry I don't have the link immediately handy ... I'll post it tomorrow if you'd like it)

    Not sure if that is of any help? but good luck anyway.

    Richard

     

    Wednesday, January 24, 2007 5:41 PM