Error Handling - VB6 To .Net
Error Handling - VB6 To .Net
Error Handling - VB6 To .Net
Error Handling - VB6 To .Net
Error Handling - VB6 To .Net
Error Handling - VB6 To .Net Error Handling - VB6 To .Net Error Handling - VB6 To .Net Error Handling - VB6 To .Net Error Handling - VB6 To .Net Error Handling - VB6 To .Net Error Handling - VB6 To .Net Error Handling - VB6 To .Net
Error Handling - VB6 To .Net Error Handling - VB6 To .Net
Error Handling - VB6 To .Net
Go Back  Xtreme Visual Basic Talk > > > Error Handling - VB6 To .Net


Reply
 
Thread Tools Display Modes
  #1  
Old 05-21-2017, 06:11 AM
SiriusProjects SiriusProjects is offline
Regular
 
Join Date: May 2006
Posts: 90
Default 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.

Thanks.
Reply With Quote
  #2  
Old 05-22-2017, 07:26 AM
SiriusProjects SiriusProjects is offline
Regular
 
Join Date: May 2006
Posts: 90
Default 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?
Reply With Quote
  #3  
Old 05-22-2017, 08:14 AM
PlausiblyDamp's Avatar
PlausiblyDampError Handling - VB6 To .Net PlausiblyDamp is offline
Ultimate Contributor

Forum Leader
* Expert *
 
Join Date: Nov 2003
Location: Newport, Wales
Posts: 2,058
Default

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.
__________________
Intellectuals solve problems; geniuses prevent them.
-- Albert Einstein

Posting Guidelines Forum Rules Use the code tags
Reply With Quote
  #4  
Old 06-05-2017, 02:19 PM
passel's Avatar
passelError Handling - VB6 To .Net passel is offline
Sinecure Expert

Super Moderator
* Guru *
 
Join Date: Jun 2003
Location: Upstate New York, usa
Posts: 8,024
Default

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.
__________________
There Is An Island Of Opportunity In The Middle of Every Difficulty.
Miss That, Though, And You're Pretty Much Doomed.
Reply With Quote
Reply

Tags
error, programming, vb6, question, .net, method, handling, started, procedure, event, move, coding, catch, vb.net, initial, mind, discovered, attempts, wrap, exception, grateful, advice, practise, probability, inside


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Error Handling - VB6 To .Net
Error Handling - VB6 To .Net
Error Handling - VB6 To .Net Error Handling - VB6 To .Net
Error Handling - VB6 To .Net
Error Handling - VB6 To .Net
Error Handling - VB6 To .Net Error Handling - VB6 To .Net Error Handling - VB6 To .Net Error Handling - VB6 To .Net Error Handling - VB6 To .Net Error Handling - VB6 To .Net Error Handling - VB6 To .Net
Error Handling - VB6 To .Net
Error Handling - VB6 To .Net
 
Error Handling - VB6 To .Net
Error Handling - VB6 To .Net
 
-->