Monday, 28 February 2011

VB.NET Error Handling


In the previous versions of VB we had several flavors of "On Error" statements to handle error in a non-structured way. But in VB.NET we can make use of the structured way of error handling with the Try & Catch statement.

Here is an example for this.

Sub
DoSomething()Try'Do SomethingCatch e As Exception'Catch the error and display it.Response.Write("An Error Occurred: " & e.toString())
Finally
'Do the final cleanup such as closing the Database connectionEnd Try
End
Sub

0 comments:

Post a Comment