Java 异常笔试题

今天在电魂的笔试碰到一道很诡异的题目

public class Main {

 public static void main(String[] args) {
     try {
         if(true)
             throw new Exception();
        System.out.println("after");
    } catch (Exception e) {
        System.out.println("exception");
        return;
    }finally
    {
        System.out.println("finally");
    }
    System.out.println("main");
 }

}

请问这道题输出什么?

当时第一印象肯定是输出exception就直接退出了,但是找不到那个答案,回来运行一下发现,finally块还真特么的运行!!

exception
finally

 

posted @ 2015-10-13 15:50  Maydow  阅读(261)  评论(0编辑  收藏  举报