• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Exception

 
lalitha kaparapu
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 170
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
R van Vliet
Ranch Hand
Posts: 144
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is IndexOutOfBoundsException a runtime exception or a checked exception???
 
kapil munjal
Ranch Hand
Posts: 298
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Kelvin Chenhao Lim
Ranch Hand
Posts: 513
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Deepak Jain
Ranch Hand
Posts: 637
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15448
42
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic