java异常小例子

package Test;

public class ExceptionTest {

    /**
     * @param args
     */
    
    public void method() throws Exception{
        
        System.out.println("你好!");
         throw new Exception();
    }
    public static void main(String[] args) {
        ExceptionTest eTest = new ExceptionTest();
        try {
            eTest.method();
        } catch (Exception e) {
            
            e.printStackTrace();
        }finally{
            System.out.println("aaa");
        }

    }

}

打印结果:

你好!
java.lang.Exception
aaa
    at Test.ExceptionTest.method(ExceptionTest.java:12)
    at Test.ExceptionTest.main(ExceptionTest.java:17)

你可能感兴趣的:(java异常小例子)