wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Exception Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Exception" Watch "Exception" New topic
Author

Exception

lalitha kaparapu
Greenhorn

Joined: Nov 05, 2007
Posts: 16
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..
Sekhar Kadiyala
Ranch Hand

Joined: Feb 17, 2004
Posts: 170
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.

Hope this helps! and good luck with the exam!


PMP CSQA SCJP SCWCD SCBCD INS 21 INS 23
R van Vliet
Ranch Hand

Joined: Nov 10, 2007
Posts: 144
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.
lalitha kaparapu
Greenhorn

Joined: Nov 05, 2007
Posts: 16
Is IndexOutOfBoundsException a runtime exception or a checked exception???
kapil munjal
Ranch Hand

Joined: May 11, 2004
Posts: 298
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.


Kapil Munjal
SCJP 1.4, SCWCD 1.4
Kelvin Chenhao Lim
Ranch Hand

Joined: Oct 20, 2007
Posts: 513
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.


SCJP 5.0
Deepak Jain
Ranch Hand

Joined: Aug 05, 2006
Posts: 637
IndexOutOfBoundsException is a runtime exception.
java.lang.Object
java.lang.Throwable
java.lang.Exception
java.lang.RuntimeException
java.lang.IndexOutOfBoundsException


SCJP, SCWCD, SCBCD
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14111
    
  16

Originally posted by lalitha kaparapu:
Is IndexOutOfBoundsException a runtime exception or a checked exception???

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.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
 
wood burning stoves
 
subject: Exception