
692 Chapter 14 • Upgrading Visual Basic Applications to .NET
Finally
<Cleanup Code>
'Contains cleanup code
End Try
Consider the following code fragment that demonstrates how to implement a
Try…Catch…Finally in a Visual Basic program.
Try
result = intVar1 / intVar2
Catch ex as System.OverflowException
Msgbox (ex.Message)
Finally
End Try
The statement that divides two integers is included in the Try block because
there might be a situation when the denominator could be zero.The Catch block
is defined with an object of the specific exception type.This is the exception we
expect the code to throw. Once the exception is caught, you can display a
custom error message ...