
316
|
Chapter 15: The HttpException Class
This is the Title of the Book, eMatter Edition
Copyright © 2008 O’Reilly & Associates, Inc. All rights reserved.
GetHttpCode
integer = HttpException.GetHttpCode( )
Returns an integer containing the HTTP status code contained within the excep-
tion. For most exceptions thrown by the ASP.NET intrinsic objects, this integer
will be 500, indicating an HTTP server error.
Parameter
integer
An integer variable to receive the HTTP code from the method.
Example
The code example causes an exception by calling Server.Execute on a page that
does not exist. The exception is then caught and the HTTP status code is
displayed by calling GetHttpCode:
Sub Page_Load( )
Try
Server.Execute("Foo.aspx")
Catch HttpEx As HttpException
Message.Text = "ERROR:<br/>"
Message.Text &= "Http Status Code: " & _
HttpEx.GetHttpCode( ) & "<br/>"
End Try
End Sub
Notes
This method is most useful for custom exceptions raised in methods that make
HTTP calls, since it allows you to pass back the HTTP result code (404 for not
found, 403 for access denied, etc.) to the calling client.
ToString
string = HttpException.ToString( )
Returns a string containing the fully qualified name of the exception, the error
message (if available), the name of the inner exception, and the stack trace.
Parameter
string
A string variable to receive the value from the method.
Example
The code example causes an exception by attempting ...