Writing an Exception Handler by Using Try...Catch...Finally

Exception handlers allow you to determine how an exception is treated, rather than rely on Visual Basic’s default behavior, which is to display the exception and terminate the application. As I mentioned earlier, Visual Basic .NET supports structured exception handling in the form of a Try...Catch...Finally structure. This structure has the following syntax—see Table 10-2 for a description of each component.

						Try
   
’ Statements to try.

Catch [exception 
						As 
						type] [When 
						expression]
   ’ Statements to run when an exception is thrown.

Finally
    ’ Statements to run when execution leaves any other block in the     ’ structure, such as Try or Catch. These statements run regardless    ’ of whether an exception occurred. ...

Get Practical Standards for Microsoft® Visual Basic® .NET, Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.