• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

RuntimeException

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is RuntimeException??Can we consider all the exceptions which occur at runtime are RuntimeExceptions like ArrayIndexOutOfBoundsException.What is the difference between JVM thrown exceptions and RuntimeExceptions??JVM thrown Exceptions also occur at runtime.I am confused with these two types of exceptions ..
Can anyone clarify this??
Thanks in advance..
 
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In general, an exception happens because some resource is not available or some other condition required for correct execution is not present

A checked exception must be caught somewhere in your code. If you invoke a method that throws a checked exception but you don't catch the checked exception somewhere, your code will not compile. That's why they're called checked exceptions; the compiler checks to make sure that they're handled or declared.

A runtimeException is not handled by compiler, it could come as a programming logic, like if you try to access array element, which index is greater than the size of array(ArrayIndexOutOfBound Exception). So user has to handle this kind of exception by his/her logic.If not, the program will not execute at runtime.

One more thing checked exception is handled at compile time(when you try to compile your file for ex javac filename), but runtime exception will occur at runtime(when you execute your program for ex Java filename)
 
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
There are two kinds of exceptions in Java: checked exceptions and unchecked exceptions.

For checked exceptions, the compiler checks that you handle them appropriately, either with a catch block or by declaring "throws ..." in the method that might pass on the exception.

For unchecked exceptions, the compiler doesn't check this.

All exceptions that inherit from RuntimeException are unchecked exceptions. Exceptions that do not inherit from RuntimeException are checked exceptions.

See: The Java Tutorials - Exceptions
 
reply
    Bookmark Topic Watch Topic
  • New Topic