Try-catch-Finally in VB.NET

In this article I will explain you about Try-catch-Finally in VB.NET
  • 2599

If you are interested in executing a certain block of code irrespective of whether an exception occurs and you do not worry about catching an exception, then you'll likely want to use the try-finally statement. However, we do not recommend using this statement because you will not be able to see what the exception is about. Instead, you should use the try-catch-finally statement. The given below example shows the structure of the Try-Finally block:

Example of Try-catch-Finally Syntax

Try
' Statement which can cause an exception.
Catch Ex As Type
' Statements for handling the exception
Finally
End
Try 'Any cleanup code

First the try block is executed, and then the finally block is executed, irrespective of whether an exception occurs or not. Even if a goto statement is present in the try block, the control gets transferred to the label in the goto statement only after executing the finally block.

Conclusion


Hope this article would have helped you in understanding Try-Catch-Finally in VB.NET

Categories

More Articles

© 2019 DotNetHeaven. All rights reserved.