异常处理

 

package com.chinadays.learn;

public class TestException {

    public static void main(String[] args) {
        try {
            int i = 0;

            System.out.println(10 / i);
        } catch (Exception e) {
            System.out.println("TestException:" + e.toString());
            System.out.println("Test:" + e.getMessage());
            e.printStackTrace();

        }
    }
}

 

异常处理  输出堆栈内的信息:

 

TestException:java.lang.ArithmeticException: / by zero
Test:/ by zero
java.lang.ArithmeticException: / by zero
at com.chinadays.learn.TestException.main(TestException.java:9)

posted @ 2017-01-20 17:15  smallyaohailu  阅读(169)  评论(1编辑  收藏  举报