fork download
  1. class EvenException extends Exception
  2. {
  3. EvenException()
  4. { }
  5. }
  6.  
  7. class OddException extends Exception
  8. {
  9. OddException()
  10. {}
  11. }
  12.  
  13. class Test
  14. {
  15. public void check(int n) throws EvenException,OddException
  16. {
  17. if(n%2==0)
  18. {
  19. throw new EvenException();
  20. }
  21. else
  22. {
  23. throw new OddException();
  24. }
  25. }
  26.  
  27. public static void main(String args[])
  28. {
  29. try
  30. {
  31. Demo d=new Demo();
  32. d.check(8);
  33. }
  34. catch(EvenException e)
  35. {
  36. e.printstacktrace();
  37. //System.out.println("this is even");
  38. }
  39. catch(OddException o)
  40. {
  41. o.printstacktrace();
  42. //System.out.println("this is odd");
  43. }
  44. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:44: reached end of file while parsing
}
 ^
1 error
stdout
Standard output is empty