/*
 * @topic T11378 Exception demo VI
 * @brief using printStackTrace( ) and throws clause
*/

package exceptions;

public class ExceptionsMain {
    public static void main(String[] args)
            //throws ExceptionCustom
    {
        int x = 1;
        int y = 0;
        int z = -1;

        try {
            z = divide( x, y );
        } catch ( ExceptionCustom ex ) {
            String message = ex.getMessage();
            System.out.println( "MESSAGE: <begin>" + message + "<end>" );
            ex.printStackTrace();
        } 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 )
            throws ExceptionCustom
    {
        try {
            return x / y;
        } catch ( ArithmeticException ex ) {
            System.out.println( "method division by zero!" );
            throw new ExceptionCustom( ex.toString() ); // throw brand new
        } finally {
            System.out.println( "method-finally" );
        }
    }
}//class ExceptionsMain