• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

Exception

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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..
 
Ranch Hand
Posts: 170
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Ranch Hand
Posts: 144
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is IndexOutOfBoundsException a runtime exception or a checked exception???
 
Ranch Hand
Posts: 298
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 513
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 637
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
IndexOutOfBoundsException is a runtime exception.
java.lang.Object
java.lang.Throwable
java.lang.Exception
java.lang.RuntimeException
java.lang.IndexOutOfBoundsException
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic