2017  Kodetalk | Feedback | Privacy Policy | Terms | About

How to differentiate between Programmer and JVM Exceptions

When I ran any java application and incase any exception occur then how come I distinguished  a JVM thrown exception from a Programmatically(does this mean, thrown by a programmer or the program) thrown exception ?

JVM Exceptions

1) ArrayIndexOutOfBoundsException

2) ClassCastException

3) NullPointerException

Programmatically thrown

1) NumberFormatException

2) AssertionError

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.

From the JavaDocs for Throwable: 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.

Because this same superclass defines all exceptions thrown by either the JVM or a programmer, you can't easily distinguish the two.

Answer is