Try Catch Finally

来源:互联网 发布:上海菜鸟网络工资多少 编辑:程序博客网 时间:2024/04/27 17:15
  • 代码
public class TryCatchFinally {    public void function(boolean ex) {        try {            System.out.println("try start");            if (ex) {                throw new NullPointerException();            }            System.out.println("try end");        } catch (Exception e) {            System.out.println("catch");        } finally {            System.out.println("finally");        }    }    public static void main(String[] args) {        TryCatchFinally test=new TryCatchFinally();        System.out.println("抛出异常:");        test.function(true);        System.out.println("不抛出异常:");        test.function(false);    }}
  • 输出
    这里写图片描述
0 0
原创粉丝点击