当前位置: 移动技术网 > IT编程>开发语言>Java > java进行error捕获和处理示例(java异常捕获)

java进行error捕获和处理示例(java异常捕获)

2019年07月22日  | 移动技术网IT编程  | 我要评论

下面给个小例子,来验证一下error的捕获。

复制代码 代码如下:

public class testcatcherror extends error{

    private static final long serialversionuid = -351488225420878020l;

    public testcatcherror(){
        super();
    }

    public testcatcherror(string msg){
        super(msg);
    }

    public static void main(string[] args) {
        try {
            throw new testcatcherror("test catch error");
        } catch (throwable t) {
            system.out.println("step in the catch ~");
            t.printstacktrace();
        }
    }
}

运行结果:

复制代码 代码如下:

step in the catch ~
testcatcherror: test catch error
at testcatcherror.main(testcatcherror.java:23)

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网