欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

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

程序员文章站 2024-02-15 19:56:10
下面给个小例子,来验证一下error的捕获。 复制代码 代码如下:public class testcatcherror extends error{ &nbs...

下面给个小例子,来验证一下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)