错误与例外之间的差异 [英] Diffence between error and exception

查看:81
本文介绍了错误与例外之间的差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


你能帮我解释一下吗
错误与异常之间的区别?


我惊呆了,发现

例外:

可以被选中或未被选中//被选中或未被选中的错误是什么意思?

错误:

始终不受检查

Hi
can you please help me explaining
Diffence between error and exception ?


i Goggled it find that

Exceptions:

Can be checked or unchecked // what is meaning of checked or unchecked error??

Errors:

Are always unchecked

推荐答案

异常通常是可以并且应该处理的意外行为.
错误通常是无法轻易解决的事情.
异常 [错误 [
Exceptions are, generally, unexpected behaviour that can, and should, be handled.
Errors are most often things that cannot be so easily worked around.
Exception[^] & Error[^]


,请参阅此链接下面的类层次结构: http://www.javamex.com/tutorials/exceptions/exceptions_hierarchy .shtml [ ^ ]

如果发生致命错误(例如,VM内存不足),通常会抛出错误及其派生类,并且不进行检查.您永远都不要处理错误.
受检查的异常是Exception类的子类(来自链接的类层次结构,但RuntimeException除外),而未检查的异常是RuntimeException类的子类(RuntimeException本身未受检查).从语法上看,源代码中的区别在于,在函数中检查异常的情况下,您必须捕获异常或在函数的声明中(使用throws关键字)将其声明为引发的异常.使用运行时异常,您不必处理或声明异常(在每个函数中声明NullPointerExceptions或与索引相关的异常会很愚蠢).

阅读链接,以了解在某些情况下应使用其中的哪一种. Java编码器通常在大多数情况下都会出现异常.
有关异常的更多理论,请阅读以下内容: http://en.wikipedia.org/wiki/Exception_handling#Checked_exceptions [< ^ ]
Please see the class hierarchy below this link: http://www.javamex.com/tutorials/exceptions/exceptions_hierarchy.shtml[^]

Errors and its derivatives are usually thrown in case of fatal errors (for example VM out of memory) and these are unchecked. You should never handle errors.
Checked exceptions are the subclasses of the Exception class (from the linked class hierarchy, except the RuntimeException) while unchecked exceptions are the subclasses of the RuntimeException class (RuntimeException itself is unchecked). In the source code syntactically the difference is that in case of checked exceptions in a function you have to either catch the exception or declare it as a thrown exception in the declaration of the functions (with the throws keyword). With runtime exceptions you don''t have to handle or declare the exception (it would be silly to declare NullPointerExceptions or indexing related exceptions in every functions).

Read the link to find out which of these should you use in certain situations. Java coders go with normal exceptions most of the time.
For some more theory on exceptions read this too: http://en.wikipedia.org/wiki/Exception_handling#Checked_exceptions[^]


这篇关于错误与例外之间的差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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