Introduction to Exception Handling in VB.NET

An 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:

Statement 1
Statement 2
catch(Exception ex)
Statement 3
Statement 4
Statement 5
Statement 6

Statement 7

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

FREE Subscription

Subscribe to our mailing list and receive new articles
through email. Keep yourself updated with latest
developments in the industry.


Note : We never rent, trade, or sell my email lists to
anyone. We assure that your privacy is respected
and protected.

Visit .NET Programming Tutorial Homepage


Recommended Resource

“Amazon and the Amazon logo are trademarks of, Inc. or its affiliates.”

| Privacy Policy for | Disclosure | Contact |

Copyright - © 2004 - 2023 - All Rights Reserved.