C# Exception Message
Description
Exception Message
gets a message that describes the current
exception.
Syntax
Exception.Message
has the following syntax.
public virtual string Message { get; }
Example
The following code example throws and then catches an ExceptionException and displays the exception's text message using the Message property.
/*w w w . ja va 2s.co m*/
using System;
class LogTableOverflowException : Exception
{
const string overflowMessage = "overflowed.";
public LogTableOverflowException(
string auxMessage, Exception inner) :
base(String.Format("{0} - {1}",
overflowMessage, auxMessage), inner)
{
this.HelpLink = "http://java2s.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("\nMessage ---\n{0}", ex.Message);
}
}
}
The code above generates the following result.