
314
|
Chapter 15: The HttpException Class
This is the Title of the Book, eMatter Edition
Copyright © 2008 O’Reilly & Associates, Inc. All rights reserved.
Parameter
MethodBase
An instance of the
MethodBase class representing the method from which the
exception was thrown.
Example
The code example causes an exception by attempting to set a Session value on a
page for which the
EnableSessionState attribute of the @ Page directive has been
set to
False. The example code then displays the resulting error message and uses
the Name property of the MethodBase instance returned by the TargetSite prop-
erty to display the name of the method from which the exception was thrown:
<%@ Page Language="vb" EnableSessionState="false" %>
...
Sub Page_Load( )
Try
Session("foo") = "Foo"
Catch HttpEx As HttpException
Message.Text = "ERROR:<br/>"
Message.Text &= "Message: " & HttpEx.Message & "<br/>"
Message.Text &= "Target Site: " & HttpEx.TargetSite.Name & "<br/>"
End Try
End Sub
Notes
In the example, we access the Name property of the MethodBase instance
directly, without creating a separate local variable of type MethodBase. This direct
access saves us the trouble of either adding an
@ Import statement to import the
System.Reflection namespace or explicitly declaring the local variable using syntax
such as:
Dim myMethodBase As System.Reflection.MethodBase
myMethodBase = HttpEx.TargetSite
Accessing the Name property of MethodBase ...