I am getting confused in identifying whether an exception is thrown by JVM or by the Program. Why are ArrayIndexOutOfBounds and NullPointerException thrown by the JVM, whereas IllegalArgumentException thrown by the application? Can someone please explain?
if you see any method in the API which throws IllegalArgumentException, then you are sure that somewhere in the beginning of the method, it has code like this
Also you are not supposed to throw ArrayIndexOutOfBoundsException or NullPointerException on your own. It is for JVM. Just think about it, when will you need to throw these exceptions. Suppose your method says that no one MUST pass a null argument to it, then you will not write your method like this
You are supposed to code your method like this-
It's not about you CAN or not. It's about what you MUST do. You can create your method and throw NullPointerException, but it is against the standards of coding...