VB.NET On Error GoTo
On Error GoTo is an older error handling technique used in earlier versions of Visual Basic, but it is not recommended in VB.NET. It is considered unstructured error handling because it relies on the use of labels and GoTo statements to handle errors, which can lead to spaghetti code and make the code harder to maintain and debug.
The structured exception handling using Try...Catch...Finally statements provides a more robust and readable way to handle exceptions. It allows you to catch specific exceptions, handle them appropriately, and clean up resources in the Finally block, ensuring proper execution regardless of whether an exception occurs or not.
Error GoTo redirect the flow of the program in a given location.
On Error Resume Next - whenever an error occurred in runtime , skip the statement and continue execution on following statements.
Take a look at the following programVB.NET Source Code
when u execute this program you will get error message like Arithmetic operation resulted in an overflow .
See the program we put an On Error GoTo statement.Full Source VB.NET
When you execute the program you will get the message box "Control Here" . Because the On Error statement redirect the exception to the Label statement.
By using structured exception handling with Try...Catch...Finally, you can handle exceptions in a more organized and controlled manner, leading to more maintainable and reliable code.