If you are coming from Visual Badic background, you will find that the error handling mechanism is totally changed in VB.NET.
Visual Basic provides an error handling mechanism, now called 'un structured error handling'. Typically, you will place a code statement "On Error Goto ErrorHandler" on top of your code block. This means, when an error occurs, jump to the path specified by 'Errorhandler'. See the following sample code :
On Error GoTo ErrorHandler
' code that may raise an error
' Error handling code
In the above sample code, if an error occurs in the method, the program execution will jump to the ErrorHandler block. This saves your program from terminating abnormally and gives an opportunity to log the error details and show friendly message to the user.
Equivalent of On Error in VB.NET and C#
Many programmers coming from Visual Basic to .NET asks this question : "what is the equivalent of On Error in .NET ?". The answer is, there is no direct equivalent. Just for backward compatibility, VB.NET supports the "On Error" statement. This is not available in C#. Even though "On Error" statement is supported in VB.NET, you are strongly encouraged to use the new structured exception handling mechanism provided by the .NET Framework.
The above sample code can be re written in VB.NET as shown below :
Private Sub MyMethod()
' code that can raise an error
Catch ex As Exception
' code to handle the exception.
Read the other articles related 'Exception handling' to find more about the structured exception handling in .NET.