How to: Display an Exception's Message in Visual Basic

The exception object includes a number of properties that help identify the code location, the type, the Helpfile URL, and the reason for the exception. One of these, the Message property, describes the current exception.

To display the string associated with an exception

  • Use the Message property to display information about the current exception. This example catches a WebException and displays the associated message.

    
    Try
        Throw New System.Net.WebException
    Catch ex As System.Net.WebException
        MsgBox("An exception occurred:" & vbCrLf & ex.Message)
    End Try
    
    
    
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2015 Microsoft