
Message | 311
HttpException
Class
This is the Title of the Book, eMatter Edition
Copyright © 2008 O’Reilly & Associates, Inc. All rights reserved.
Example
The code example creates two exceptions, the second of which is created with an
overloaded constructor that sets the InnerException property to the first excep-
tion. The code throws the second exception, which is caught by the
Catch
statement. The Catch block then displays the error messages of both the outer and
inner exceptions:
Sub Page_Load( )
Try
Dim myHttpEx As _
New HttpException("This is a nested exception")
Throw New HttpException("Threw an exception from Page_Load", _
myHttpEx)
Catch HttpEx As HttpException
Dim InnerHttpEx As HttpException
InnerHttpEx = CType(HttpEx.InnerException, HttpException)
Message.Text = "ERROR:<br/>"
Message.Text &= "Message: " & HttpEx.Message & "<br/>"
Message.Text &= "Inner Exception Message: " & _
InnerHttpEx.Message & "<br/>"
End Try
End Sub
Notes
The InnerException property allows exceptions to be nested, which can allow
developers to track down the root cause of an exception, even when multiple
exceptions are thrown. Because the InnerException property is inherited from the
Exception class, other types of exceptions can be nested within an HttpException,
and HttpExceptions can be nested within other exception types. The InnerExcep-
tion property can only be set manually through one of the overloaded
constructors ...