aspose file tools*
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


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "RuntimeException" Watch "RuntimeException" New topic
Author

RuntimeException

lalitha kaparapu
Greenhorn

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: 13884
    
  10

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 7 API documentation
Scala Notes - My blog about Scala
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: RuntimeException
 
Similar Threads
exceptions
RunTimeException or checked Exception?
exam lab q-9(excepton handling)
Doubt in exceptions thrown by JVM and by programmer
overriding methods: doubt