Name
Source
Synopsis
string = HttpException.Source HttpException.Source = string
Sets or returns a string representing the source of the exception. For custom exceptions that you create and throw, this code may be set to the name of the method and/or class from which the exception is thrown.
Parameters
-
string
A string that will receive the value from the property.
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 source:
<%@ 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 &= "Source: " & HttpEx.Source & "<br/>" End Try End Sub
Notes
In the example, the Source property returns the value System.Web as the source of the Exception, which is not very specific. When creating and throwing your own custom exceptions, be as specific as possible with error messages and source descriptions. Just remember that providing specific information about an exception you’re throwing is no substitute for handling the exception condition within your code instead of throwing an exception. If you have sufficient information about what went wrong to correct the problem, doing so is almost always preferable to throwing an exception that will interrupt ...
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.