C# Exception Source
Description
Exception Source
gets or sets the name of the application
or the object that causes the error.
Syntax
Exception.Source
has the following syntax.
public virtual string Source { get; set; }
Example
The following code example throws an Exception that sets the Source property in its constructor and then catches the exception and displays Source.
// www . j ava 2 s. c o m
using System;
class LogTableOverflowException : Exception
{
const string overflowMessage = "The log table has overflowed.";
public LogTableOverflowException(
string auxMessage, Exception inner ) :
base( String.Format( "{0} - {1}",
overflowMessage, auxMessage ), inner )
{
this.HelpLink = "http://msdn.microsoft.com";
this.Source = "Exception_Class_Samples";
}
}
class OverflowDemo
{
public static void Main()
{
try{
throw new LogTableOverflowException(
String.Format( "Record \"{0}\" was not logged.",
"asdf" ), null );
}catch( Exception ex ){
Console.WriteLine( "\nSource ---\n{0}", ex.Source );
}
}
}
The code above generates the following result.