orCode:public class ThrowTest{ public static void main(String[] args){ try { int i = 7 / 0; }catch(Exception e){ System.out.println(e.getClass().getName()); System.out.println(e.getMessage()); } } }
The main difference to yours is that mine doesn't run the hierarchy. In your example your code would print:Code:public class ThrowTest{ public static void main(String[] args){ try { int i = 7 / 0; } catch(ArithmeticException e) { System.out.println("ArithmeticException"); System.out.println(e.getMessage()); } catch(ClassCastException e) { System.out.println("ClassCastException"); } // ... } }
while mine would only printArithmeticException
Integer division by zero
RuntimeException
Integer division by zero
Exception
Integer division by zero
Throwable
Integer division by zero
ArithmeticException (or java.lang.ArithmeticException)
Integer division by zero




CornedBee
Reply With Quote