/*
 * @topic T11375 Exception demo II
 * @brief ArithmeticException more specific than Exception 
*/

package exceptions;

public class ExceptionsMain {
    public static void main(String[] args) {
        int x = 1;
        int y = 1;
        int z = -1;
        try {
            z = x / y;
        } catch ( ArithmeticException ex ) {
            System.out.println( "first division by zero!" );
            ex.printStackTrace();
            return;
        } catch ( Exception ex ) {
            System.out.println( "generic Exception!" );
        } finally {
            System.out.println( "first time z is " + z );
        }
        
        y = 0;
        try {
            z = divide( x, y );
        } catch ( ArithmeticException ex ) {
            System.out.println( ex.getMessage() );
            ex.printStackTrace();
        } finally {
            System.out.println( "second time z is " + z );
        }
    }

    public static int divide( int x, int y ) {
        return x / y;
    }
}//class ExceptionsMain