java基礎 try catch finally

public static void main(String[] args) {
        try{
            System.out.println("2222");
            return;
        }catch (Exception e){
            System.out.println("333");
            return;
        }finally {
            System.out.println("444");
        }

    }


2222
444
public static void main(String[] args) {
        try{
            System.out.println("2222");
            throw new Exception("exception111");
        }catch (Exception e){
            System.out.println("333");
            return;
        }finally {
            System.out.println("444");
        }

    }

2222
333
444
public static void main(String[] args) throws Exception {
        try{
            System.out.println("2222");
            throw new Exception("exception111");
        }catch (Exception e){
            System.out.println("333");
            throw new Exception("excep333");
        }finally {
            System.out.println("444");
        }

    }

2222
333
444
Exception in thread "main" java.lang.Exception: excep333
	at com.zte.daas.webapp.AllTests.main(AllTests.java:21)

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章