Xtreme Visual Basic Talk

Xtreme Visual Basic Talk (http://www.xtremevbtalk.com/)
-   .NET General (http://www.xtremevbtalk.com/-net-general/)
-   -   Error Handling - VB6 To .Net (http://www.xtremevbtalk.com/-net-general/328640-error-handling-vb6-net.html)

SiriusProjects 05-21-2017 06:11 AM

Error Handling - VB6 To .Net
Hi All,

I come from a background where I did extensive programming using VB6. I have now move to .Net and have to say I am really enjoying the programming experience with VB.net.

One question I do have and to be honest I used to ask this same question a lot when I was using VB6. Where and when do you use error handling?

When I started programming using VB6, the temptation was to error handle ever procedure, method and event. But as I became more experienced I started to reduce the amount of error handling and only placed it where there was a high likelihood of an error being generated.

I have continued to use 'On Error Goto" coding in my initial programming attempts in VB.net, but have now discovered the "Try, Catch" method and want to move over to this. But the same question is on my mind. Do you wrap every procedure, method and event inside a "Try, Catch" or do you only use it where there is a high probability of an exception being called?

I want to improve my coding and ensure that I adhere to best practise in all areas of .Net programming, so I would be grateful for any advice you may have.


SiriusProjects 05-22-2017 07:26 AM

Yes or No
A simple "Yes" or "No" will do.

Do you place error handling into every procedure, method, event, etc or use your own judgement and only place it where a error/exception could occur?

PlausiblyDamp 05-22-2017 08:14 AM

Personally I would only put a try catch around code when I am expecting it to fail, if it is something I can avoid (validating data etc) then I would always prefer to avoid handling errors.

When I do use try catch I would also catch just the specific errors I know how to deal with in that location, if I can't do anything then I will let the error bubble up and be caught higher up the call stack. This prevents low level routines catching errors they can't deal with but hiding problems from higher routines that could deal with them.

I would also get into the habit of providing an application wide default error handler to catch any unhandled exceptions and as a minimum log them somewhere and apologise before exiting.

passel 06-05-2017 02:19 PM

Perhaps one place you may want to always have a Try Catch block, especially if you do a lot of initialization from the Form's Load event, is in the Form's Load event. There are situations where if an exception happens in the Form's Load event, the exception is quietly ignored and your Load event code will exit prematurely with no indication of a problem, other than some initialization you expected to be done is not done and may cause you problems later.

All times are GMT -6. The time now is 08:52 PM.

Powered by vBulletin® Version 3.8.9
Copyright ©2000 - 2018, vBulletin Solutions, Inc.
Search Engine Optimisation provided by DragonByte SEO v2.0.15 (Lite) - vBulletin Mods & Addons Copyright © 2018 DragonByte Technologies Ltd.
All site content is protected by the Digital Millenium Act of 1998. Copyright©2001-2011 MAS Media Inc. and Extreme Visual Basic Forum. All rights reserved.
You may not copy or reproduce any portion of this site without written consent.