Java is divided into runtime exception ( RuntimeException ) and check exception ( checked exception )
for many exceptions, statements like throw new Exception ()
declare an exception in the program.
if it is a runtime exception, it can be handled in the program or not. For checking an exception, you must handle it
. There is a problem, that is, how do you throw an exception when it is not declared? Like
obj.method();
when obj==null
, NPE is definitely thrown, but there is no such statement
method ()
.
method{
ifthis==null
throw new NullPointException();
}
how is a Exception
like this implemented
is it done in JVM ?
so if you did it in JVM , then JVM did this for which check exceptions, and how did JVM do it?
@ Jian Xin is right. The problem here is really obvious. Obj is empty, and there is no way to find method.
but I also want to know how the NullPointException is thrown when "null.method ()", and the Java code doesn"t see where the NullPointException? is thrown.