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 SubNotes
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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access