Handling errors

tottino

New member
Joined
Mar 26, 2009
Messages
2
Programming Experience
Beginner
guyz.. can i suggest that someone add a lessons about
error handling in vb.net?
please cuz i'm really facing a huge problems with their handling
 
Error handling in .Net is handled by using Try/Catch blocks, which should always be used when accessing things outside of your app (files on the HDD, databases, webservices, etc) where your program may not have access to it, which will cause an exception.

That being said, using Try/Catch blocks for crappy code (casting, conversions, etc) is never a good idea. Here's an example of using a Try/Catch block:
VB.NET:
Try
    'Code that may cause an error
    'Like a sql server database
Catch SqlEx As SqlException 'A sql specific exception
    'Code to handle the exception
Catch ex As Exception 'A general one if the exception isnt one of the above ones
    'Code to handle the exception
End Try
 
Introduction to Exception Handling You can read more about what JB explained by following the "Structured Exception Handling" topic.
Related to error handling is validation, to prevent errors from occuring at an earlier stage rather than catching them.
 

Latest posts

Back
Top