permaculture playing cards
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes RuntimeException 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 "RuntimeException" Watch "RuntimeException" New topic


lalitha kaparapu

Joined: Nov 05, 2007
Posts: 16
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

Joined: Mar 26, 2007
Posts: 74
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)

Gunjan Kumar
SCJP 1.5
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 15092

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

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
I agree. Here's the link:
subject: RuntimeException
It's not a secret anymore!