Exception throw and catch 2 : Exception Throw « Language Basics « C# / C Sharp






Exception throw and catch 2

Exception throw and catch 2
/*
Learning C# 
by Jesse Liberty

Publisher: O'Reilly 
ISBN: 0596003765
*/
 using System;

 namespace ExceptionHandling
 {
    public class TesterExceptionHandling3
    {

       static void Main()
       {
           Console.WriteLine("Enter Main...");
           TesterExceptionHandling3 t = new TesterExceptionHandling3();
           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...");
            try
            {
                Console.WriteLine("Entering try block...");
                Func2();
                Console.WriteLine("Exiting try block...");
            }
            catch
            {
                Console.WriteLine("Exception caught and handled!");
            }
            Console.WriteLine("Exit Func1...");
        }

        public void Func2()
        {
            Console.WriteLine("Enter Func2...");
            throw new System.Exception();
            Console.WriteLine("Exit Func2...");
        }
    }
 }


           
       








Related examples in the same category

1.Throwing Your Own Exceptions
2.Intentionally throws an error to demonstrate Just-In-Time debuggingIntentionally throws an error to demonstrate
              Just-In-Time debugging
3.Exception throwsException throws
4.Exception throw and catchException throw and catch
5.illustrates creating and throwing an exception objectillustrates creating and throwing an exception object
6.Demonstrates rethrowing an exception from a methodDemonstrates rethrowing an exception from a method
7.Let the C# runtime system handle the errorLet the C# runtime system handle the error
8.Manually throw an exceptionManually throw an exception
9.Rethrow an exceptionRethrow an exception