This program demonstrate the throwing a new exception of type ArgumentException. Just create a new exception and through it. to catch this type of specific exception specify in catch block.
using System;
namespace ConsoleHub
{
class Programs
{
static void Main(string[] args)
{
try
{
Print_String(null);
}
catch (System.ArgumentException ex)
{
Console.WriteLine("{0}", ex.Message);
}
Console.ReadLine();
}
private static void Print_String(string str)
{
if (str == null)
{
throw new ArgumentNullException("str");
}
else
{
Console.WriteLine(str);
}
}
}
}
No comments:
Post a Comment