Madhuri Koti

Madhuri Koti

  • NA
  • 1
  • 1.5k

c# exception handling

Apr 24 2013 9:34 AM
Exceptions can be used to indicate problems that occur when an object is being constructed
.Write a C# program that shows a constructor passing information about constructor failure to an
exception handler that occurs after a try block. The exception thrown also should contain the
arguments sent to the constructor.

i have got the following solution, but m stuck and dunno how to proceed

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

 

       public class Test

       {

           public static void Main()

           {

        

            try

               {

                   Sample e = new Sample();

               }

               catch( SampleException some )

               {

                Console.WriteLine("Exception Caught!");

               }

        

           }

       }

        

       class Sample

       {

           int x = 0;

           public SomeException()

        {

               if(x == 0)

               throw new SampleException();

           }

    }



Answers (2)