Introduction to Exception Handling in VB.NETAn exception
in VB.NET is a runtime error that often occurs unpredictably. In order
to correct or debug those exceptions, VB.NET uses a method called exception
handling.
In short, exception handling in VB.NET is a method to prevent unexpected errors such as loss of network while your application wants to communicate with other computers and when disk might be full when you want to write into a file. In ordinary Visual Basic you can use only unstructured event handling to deal with errors. You can place On Error statement at the beginning of a block of code to handle errors in that particular block. In VB.NET you can use both structured and unstructured exception handling. The exceptions in the CLR are derived from a single base class. In structured exception handling you can use the Try, Catch, and Finally block of statements. The syntax for the structure exception handling is: try The Finally statement is optional but it is executed even if there is an exception or not in the code. Structured exception handling is a fundamental part of Common Language Runtime (CLR) that makes structured exception handling in VB.NET language independent. This means that you can invoke exceptions in one language and fix it in another language. Structured exception handling in VB.NET is also able to fix the .Net components that are raised remotely. Moreover, structured exception handling in VB.NET uses a hierarchical system, which means that exceptions can be layered. In addition you do not need to check for the return values from every function or method call in structured exception handling in VB.NET. You too can raise exceptions using Throw statement. Related Article
: How to
Use Structured Exception Handling in .NET
|