An exception that's never caught will cause application to stop running.This is the line I found in K & B.But I read in some book that if the exception is never caught in our program that exception is propagated to the JVM.How JVM handles this exception.Will the JVM cause the application to stop running?? Can anyone please clarify this..
Hi Lalitha, Both the statements are true. When an exception is not caught by the program, it gets propagated all the way to the top most parent class and then ti would throw it up causing the application to come to stop. For example, if you dont have try and catch block for the ArrayIndexOutOfBoundsException, and if the code is trying to access some unavailable index, then the error is propagated thru all the classes until it reaches the top most parent and then the error is thrown back on the screen.
Exceptions don't refer to the Thread priorities, instead if an exception is thrown and not being caught is returned to the JVM and is handled by the JVM. As the control goes out of the application, it results in application being stopped.
Originally posted by R van Vliet: Isn't it so that this only applies if an exception in the main thread is uncaught? If another thread generates an uncaught exception the program doesn't quit if memory serves.
In general, if an exception's not caught by any of the methods in a thread's current stackframe list, that thread will be terminated by the JVM. The JVM itself will only exit if all non-daemon threads have terminated.
Thus, you're correct in saying that an uncaught exception in a thread doesn't necessarily cause the whole JVM to exit. However, there's nothing special about the main thread; it can also be terminated by an uncaught exception without causing the JVM to exit, as long as at least one other non-daemon thread is still running.
You can find that out quickly by looking at the API documentation. If an exception has RuntimeException as one of its superclasses, then it is an unchecked exception. Otherwise it is a checked exception.