Advertisement
alexarcan

assignment6b

Dec 5th, 2014
396
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.69 KB | None | 0 0
  1. class MyException extends Exception
  2. {
  3.     private static int exceptionNb = 0;
  4.    
  5.     public MyException(String exceptionString)
  6.     {
  7.         super(exceptionString);
  8.         exceptionNb++;
  9.     }
  10.     public static int exceptionCount(){ return exceptionNb;}
  11. }
  12.  
  13. class MyExceptionMain
  14. {
  15.     public static void main(String[] args)
  16.     {
  17.         MyException e1= new MyException(new String("abcd"));
  18.        
  19.         System.out.println(e1.getMessage());
  20.         System.out.println(e1.exceptionCount());
  21.        
  22.         e1 = new MyException("efgh");
  23.         System.out.println(e1.getMessage());
  24.         System.out.println(e1.exceptionCount());
  25.        
  26.         e1 = new MyException("klmn");
  27.         System.out.println(e1.getMessage());
  28.         System.out.println(e1.exceptionCount());
  29.        
  30.     }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement