Lastly, the point where an exception is thrown and the point where it??™s handled can be disjointed
and have no connection to each other. Thus it can be difficult when reading code to
determine where an exception will get caught and handled. These reasons alone are enough
for you to stick to traditional techniques when managing normal execution flow.
Mechanics of Handling Exceptions in VB 2008
If you??™ve ever used exceptions in other C-style languages such as C++, Java, or even C/C++ using
the Microsoft structured exception-handling extensions (__try/__catch/__finally), then you??™re
already familiar with the basic syntax of exceptions in Visual Basic (VB). In that case, you may
find yourself skimming the next few sections or treating the material as a refresher.
Syntax Overview of the Try Statement
The code within a Try block is guarded against exceptions such that, if an exception is thrown,
the runtime will search for a suitable Catch block to handle the exception. Whether a suitable
Catch block exists or not, if a Finally block is provided, the Finally block will always execute,
no matter how execution flow leaves the Try block. Let??™s look at an example of a Try statement:
Imports System
Imports System.Collections
Imports System.
Pages:
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231