프로그래밍

인터페이스

Dilrong 2013. 11. 13. 17:12
public class ExceptionTest {
    public static void main(String[] args) {
        int x = 10, y0 = 0, y1 = 2, z = 10;
         
        System.out.println("main: z= " +z); 
        try{ 
            System.out.println("try: before 'divide by 0' "); 
            //주석전 : catch(ArithmeticException): java.lang.ArithmeticException: / by zero 
            //주석후 : try: afer 'divide by 0'  
            //z = x/y0;  
            z = x/y1; 
            System.out.println("try: afer 'divide by 0' "); 
        } 
        catch(ArithmeticException e) { 
            System.out.println("catch(ArithmeticException): " +e); 
        } 
        catch(Exception e) { 
            System.out.println("catch(Exception): "+e); 
        } 
        finally{ 
            System.out.println("finally: z =" +z); 
        } 
        System.out.println("main: z=" +z); 
    } 
}
반응형