/* * @topic T11376 Exception demo III * @brief using printStackTrace( ) and re-throw */ package exceptions; public class ExceptionsMain { public static void main(String[] args) { int x = 1; int y = 0; int z = -1; try { z = divide( x, y ); } catch ( ArithmeticException ex ) { String message = ex.getMessage(); System.out.println( "MESSAGE: <begin>" + message + "<end>" ); ex.printStackTrace(); } finally { System.out.println( "in main z is " + z ); } } public static int divide( int x, int y ) { try { return x / y; } catch ( ArithmeticException ex ) { System.out.println( "method division by zero!" ); throw ex; // re-throw } finally { System.out.println( "method-finally" ); } } }//class ExceptionsMain