J
Jack
Does java NullPointerException always cause crash?
Thanks.
Thanks.
Does java NullPointerException always cause crash?
Does java [sic] NullPointerException always cause crash?
Thomas said:Theoretically you are right. However I did encounter JVM implementations
which occasionally had trouble with NullPointerException (including a
port of Sun's JVM for FreeBSD).
Peter said:Uh. You, of all people, complaining about pedantry, however irrelevant
to the question at hand?
How droll.
Lew said:Runtime exceptions are designed not to be caught, but to cause a
program to abort. It is not usual (nor, in my opinion, usually
correct) to handle runtime exceptions routinely.
To be precise, in many JVM, null references are not checked before
access; instead, the access is trapped by the OS, which generates a
system-level exception (on Unix-like systems, a SIGSEGV or SIGBUS
signal). The JVM intercepts that signal, obtains the faulty code
address, and converts the signal into a NullPointerException which is
then thrown in the offending thread.
Come on, guys, Jcheeze! The OP clearly meant crash of his program, not the JVM.
Peter said:Have you in fact helped the querent? After all, you stated that a
NullPointerException always terminates the program. Even ignoring that
you've arbitrarily chosen a different definition of "crash" than Roedy
chose, however more likely that definition might be to be correct it
still remains that your conclusion wasn't precisely correct.
That is, I will (pedantically) point out that you claimed that
"[exceptions] that YOU catch and deal with properly will not [cause
termination of a program]". Clearly implying that exceptions YOU do NOT
catch and deal with property WILL cause termination of the program.
Except that there are examples of areas of the Java API where exceptions
are caught on your behalf, not by YOU.
(Emphasis added above for clarity)
Okay, you may now feel free to complain about my pedantry.
Roedy said:If you are into it, let's tighten up the vocabulary, create history,
and I will document the new precise meanings, then Lew can have fun
razzing the newbies when they use the terms improperly.
it never causes a crash. Only a big in the JVM causes a crash. If
you don't catch is the run time will, and print out a stack trace.
Peter said:That is, I will (pedantically) point out that you claimed that
"[exceptions] that YOU catch and deal with properly will not [cause
termination of a program]". Clearly implying that exceptions YOU do
NOT catch and deal with property WILL cause termination of the program.
I did not say, "Exceptions that YOU catch", as you misquoted. I
I would say most programmers reserve the word "crash" for the JVM
blowing up, not just an unhandled exception.
Most business users I know rightfully understand a simple truth - theArne said:I am not so sure about that.
You write a C/C++ program that does something that makes
the machine throw an exception, so the program
crashes if it is not handled.
You write a Java program that does something
that makes the JVM throw an exception, so the
program crashes if it is not handled.
Same thing.
So if you are writing Java apps, then an unhandled
exception in Java is a crash.
But if you are writing JVM's, then you need the C/C++
code in the JVM to crash before you consider it a crash.
The number of people writing Java apps is a lot greater
than the number of people writing JVM's.
Arne
Arved said:Most business users I know rightfully understand a simple truth - the
application is either working or it's not. They don't actually use the
word "crash" often - the popular term is "outage", which is
descriptive enough. And they could really not care less whether it
was the JVM that locked up or crashed, or it was their J2EE
application that crashed, or it was their J2EE application that's in
deadlock or just glacially slow. It's all an outage.
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.