java中的错误和未检查异常的区别? [英] difference between errors and unchecked exceptions in java?

查看:181
本文介绍了java中的错误和未检查异常的区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们知道如果有任何错误或任何未经检查的异常发生,我们的程序将停止,那么它们之间有什么区别?

解决方案

错误 Javadoc:


错误是Throwable
的子类,表示一个
合理的应用程序不应该尝试$ b $的严重问题b抓住大多数这样的错误是
异常情况。 ThreadDeath
错误,虽然是正常条件,是
也是错误的子类,因为大多数
应用程序不应该尝试捕获
它。


异常 Javadoc


类Exception及其子类
是一种Throwable形式,表示
条件,一个合理的
应用程序可能想要捕获。


所以,即使没有被检查的异常需要被抓住,你可能想要。一个错误,你不想抓住。


As we know if any error or any unchecked exception occurs then our program will halt, then what are the differences between those?

解决方案

From the Error Javadoc:

An Error is a subclass of Throwable that indicates serious problems that a reasonable application should not try to catch. Most such errors are abnormal conditions. The ThreadDeath error, though a "normal" condition, is also a subclass of Error because most applications should not try to catch it.

Versus the Exception Javadoc

The class Exception and its subclasses are a form of Throwable that indicates conditions that a reasonable application might want to catch.

So, even though an unchecked exception is not required to be caught, you may want to. An error, you don't want to catch.

这篇关于java中的错误和未检查异常的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆