如何区分Programmer和JVM Exceptions [英] How to differentiate between Programmer and JVM Exceptions
问题描述
正如标题建议的那样,如何判断 JVM抛出的异常来自以编程方式(这是否意味着,由程序员或程序引发)抛出异常?
As the title suggests, how can I tell a JVM thrown exception from a Programmatically(does this mean, thrown by a programmer or the program) thrown exception ?
JVM例外
1 ) ArrayIndexOutOfBoundsException
1) ArrayIndexOutOfBoundsException
2) ClassCastException
2) ClassCastException
3 ) NullPointerException
3) NullPointerException
以编程方式抛出
1) NumberFormatException
1) NumberFormatException
2) AssertionError
2) AssertionError
非常感谢
Many Thanks
推荐答案
我不确定JVM异常是什么意思。这些都是程序员可能在任何时候抛出的运行时异常(异常 AssertionError
),尽管抛出某些异常(例如)被认为是不好的样式的NullPointerException
。关键是,除了典型用法之外,没有一个品质将您提到的两个类别分开。所有运行时异常直接或间接扩展 RuntimeException
。
I'm not sure what you mean by JVM exceptions. These are all runtime exceptions that may be thrown by the programmer at any point (exception AssertionError
), though it is considered poor style to throw certain exceptions like NullPointerException
. The point is, there's no one quality separating the two categories you mention other than their typical usage. All the runtime exceptions extend, either directly or indirectly, RuntimeException
.
来自JavaDocs for Throwable
:
From the JavaDocs for Throwable
:
只有
实例的对象(或其子类之一) )
由Java虚拟机
抛出,或者可以由Java抛出
语句抛出。
Only objects that are instances of this class (or one of its subclasses) are thrown by the Java Virtual Machine or can be thrown by the Java throw statement.
因为同一个超类定义了JVM或程序员抛出的所有异常,所以你不能轻易区分这两个异常。
Because this same superclass defines all exceptions thrown by either the JVM or a programmer, you can't easily distinguish the two.
这篇关于如何区分Programmer和JVM Exceptions的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!