Sponsored Ad

Sunday, May 6, 2012

How to Throw and Handle ArgumentException in C#

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.

How to Throw and Handle ArgumentException in C#

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

Sponsored Ad

Development Updates