Getting an Exception's Number and Description in VB.net
By: Steven Holzner
For more information on exceptions, you can use the Err object's Number and Description properties, like this:
Module Module1 Sub Main() Dim int1 = 0, int2 = 1, int3 As Integer On Error Goto Handler int3 = int2 / int1 System.Console.WriteLine("Program completed...") Handler: System.Console.WriteLine("Error number {0} occurred: {1}", _ Err.Number, Err.Description) End Sub End Module
Here's what you see when you run this console application:
Error number 6 occurred: Exception of type System.OverflowException was thrown.
Tip |
You can determine the object that caused the exception using the Visual Basic Err object's Source property. This property holds the name of the object or application that caused the exception. For example, if you connect to Microsoft Excel and it generates an exception, Excel sets Err.Number to its error code for that exception, and it sets Err.Source to "Excel.Application". |
Archived Comments
Comment on this tutorial
- Data Science
- Android
- AJAX
- ASP.net
- C
- C++
- C#
- Cocoa
- Cloud Computing
- HTML5
- Java
- Javascript
- JSF
- JSP
- J2ME
- Java Beans
- EJB
- JDBC
- Linux
- Mac OS X
- iPhone
- MySQL
- Office 365
- Perl
- PHP
- Python
- Ruby
- VB.net
- Hibernate
- Struts
- SAP
- Trends
- Tech Reviews
- WebServices
- XML
- Certification
- Interview
categories
Related Tutorials
Using Resume Next and Resume Line in VB.net
Using On Error GoTo 0 in VB.net
Getting an Exception's Number and Description in VB.net
Raising an Exception Intentionally in VB.net
Exception Filtering in the Catch Block in VB.net
Using Multiple Catch Statements in VB.net
Throwing an Exception in VB.net
Throwing a Custom Exception in VB.net
Changes in Controls from VB6 to VB.net
Unstructured Exception Handling in VB.net