/*
this is a demo of stack unwinding
it produces the following output:

  Method throwException()
  Finally executed in throwException()
  Exception handled in main

*/

public class UsingExceptions2
{
  public static void main(String[] args)
  {
    try
    {
      throwException();
    }
    catch(Exception e)
    {
      System.out.println("Exception handled in main");
    }
  }

  public static void throwException() throws Exception
  {
    try
    {
      System.out.println("Method throwException()");
      throw new Exception();
    }
    catch(RuntimeException e)
    {
      System.out.println("Exception handled in throwException()");
    }
    finally
    {
      System.out.println("Finally executed in throwException()");
    }
  }
}
