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)