Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

RuntimeException

 
lalitha kaparapu
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • 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..
 
Gunjan Kumar
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • 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)
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Pie
Posts: 15369
40
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic