Name
ErrorCode
Synopsis
integer = HttpException.ErrorCode
Returns an integer
representing the Win32 error code or HRESULT
of
the exception. This property is especially useful in situations when
you are working with COM objects through COM Interop and need to
return or evaluate the HRESULT
returned from a COM
object failure. When creating HttpException instances in your own
code, you can use one of two overloaded constructors (shown earlier
in Section 15.1) to set
this property for HttpExceptions that you throw.
Parameters
-
integer
An integer that will receive the
HRESULT
or Win32 error code from the property.
Example
The code example uses the Page_Load event handler to throw an HttpException with a custom error message and error code, and then uses structured exception handling to catch the exception and display the error message and error code as the text of an ASP.NET Label control:
Sub Page_Load( ) Try Throw New HttpException("Threw an error from Page_Load", 100) Catch HttpEx As HttpException Message.Text = "ERROR:<br/>" Message.Text &= "Message: " & HttpEx.Message & "<br/>" Message.Text &= "Error Code: " & HttpEx.ErrorCode & "<br/>" End Try End Sub
Notes
While the ErrorCode property is primarily useful when working with COM objects, this property is also set by the ASP.NET intrinsic objects when an exception is thrown.
Get ASP.NET in a Nutshell now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.