C# Exception Exception()
Description
Exception Exception()
initializes a new instance of
the Exception class.
Syntax
Exception.Exception()
has the following syntax.
public Exception()
Example
The following code example derives an Exception that uses a predefined message.
using System;//from ww w . j a va2s .co m
class NotEvenException : Exception
{
public NotEvenException( ) :
base( "The argument to a function requiring " +
"even input is not divisible by 2." )
{ }
}
class NewExceptionDemo
{
public static void Main()
{
try{
throw new Exception( );
throw new NotEvenException( );
}
catch( Exception ex )
{
Console.WriteLine( ex.ToString( ) );
}
}
}
The code above generates the following result.