当前位置:主页 > 软件编程 > JAVA代码 >

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

时间:2021-05-07 10:49:36 | 栏目:JAVA代码 | 点击:

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

您可能感兴趣的文章:

相关文章