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)

 

你可能感兴趣的:(java)