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)


阅读排行
- 1Java Swing组件BoxLayout布局用法示例
- 2java中-jar 与nohup的对比
- 3Java邮件发送程序(可以同时发给多个地址、可以带附件)
- 4Caused by: java.lang.ClassNotFoundException: org.objectweb.asm.Type异常
- 5Java中自定义异常详解及实例代码
- 6深入理解Java中的克隆
- 7java读取excel文件的两种方法
- 8解析SpringSecurity+JWT认证流程实现
- 9spring boot里增加表单验证hibernate-validator并在freemarker模板里显示错误信息(推荐)
- 10深入解析java虚拟机




