Saturday, July 21, 2007

Exception Handling : Throw

Throw:
Thrown exception is an object whose class is derived from System.Exception
When an exception is thrown, program looks for the catch statement that handles the exception

Code Listing: Throw


using System;

public class ThrowTest
{

public static void Main()
{
string s = null;

if (s == null)
{
throw(new ArgumentNullException());
}

Console.Write("The string s is null"); // not executed
}
}

No comments: