How to: Throw an Exception in Visual Basic
This example throws an ApplicationException exception.
Example
Throw New ApplicationException
' Code to react to possible causes of the exception.
This code example is also available as an IntelliSense code snippet. In the code snippet picker, it is located in Visual Basic Language. For more information, see How to: Insert IntelliSense Code Snippets.
Compiling the Code
This example requires:
- A reference to the System namespace.
Robust Programming
Unhandled exceptions can cause application execution to halt. Use Try…Catch blocks to anticipate and handle possible exceptions.
See Also
Tasks
How to: Catch an Exception in Visual Basic
How to: Test Code with a Try…Catch Block in Visual Basic
How to: Clean up Resources with a Try…Finally Block in Visual Basic
How to: Filter Errors in a Catch Block in Visual Basic
How to: Check an Exception's Inner Exception (Visual Basic)
Troubleshooting Exception Handling (Visual Basic)
Reference
Throw Statement (Visual Basic)
Concepts
Choosing When to Use Structured and Unstructured Exception Handling (Visual Basic)