Like real estate, there are three things that are most important about coding structured error handling in VB.NET.
- Location
- Location
- Location
In other words, the first thing to think about is where to put the error trapping in your code. Once you decide that, then you write the error handling code to intercept the errors using several different techniques and minimize the effect of bad things happening in your program.
You can use a Try-Catch error handler for ...
- Hardware
A server, modem, disk drive or printer experiences an error. Add the Try-Catch block around the statements that access the resource. - Software
If a component isn't installed or is the wrong version. Try-Catch block around where the resource is used. - Security
If the user might not have permission to access a resource, add a Try-Catch block around the statements where the resource is used.