Exception throw and catch : Exception Throw : Language Basics C# Source Code


Custom Search

C# Source Code » Language Basics » Exception Throw »

 

Exception throw and catch









    

/*
Learning C# 
by Jesse Liberty

Publisher: O'Reilly 
ISBN: 0596003765
*/

 using System;

 namespace ExceptionHandling
 {
    public class TesterExceptionHandling2
    {
       static void Main()
       {
           Console.WriteLine("Enter Main...");
           TesterExceptionHandling2 t = new TesterExceptionHandling2();
           t.Run();
           Console.WriteLine("Exit Main...");
       }
       public void Run()
       {
           Console.WriteLine("Enter Run...");
           Func1();
           Console.WriteLine("Exit Run...");
       }


        public void Func1()
        {
            Console.WriteLine("Enter Func1...");
            Func2();
            Console.WriteLine("Exit Func1...");
        }

        public void Func2()
        {
            Console.WriteLine("Enter Func2...");
            try
            {
                Console.WriteLine("Entering try block...");
                throw new System.Exception();
                Console.WriteLine("Exiting try block...");
            }
            catch
            {
                Console.WriteLine("Exception caught and handled!");
            }
            Console.WriteLine("Exit Func2...");
        }
    }
 }

           
       
    
   
  
   







HTML code for linking to this page:

Follow Navioo On Twitter

C# Source Code

 Navioo Language Basics
» Exception Throw