Runtime Exception

In java, a RuntimeException, or a class derived from it, is an UncheckedException, one which you may throw without declaring it in the throws clause of the method's signature.


See http://java.sun.com/j2se/1.4.2/docs/api/java/lang/RuntimeException.html


I interpret RuntimeException to mean "a coding defect was detected at runtime". This can occur when you are writing explicit bug-detection code, like with an assert statement. It can also occur when you are forced into handling a condition that should never occur, such as when you handle an exception that should never be thrown or implement a method that should never be called.

In the case of an exception that should never be thrown, I tend to wrap the exception in a RuntimeException, perhaps with the message "should never be thrown". Maybe there should be a subclass of RuntimeException explicitly for this purpose. (IllegalExceptionException??)

I also use RuntimeExceptions for the default case of a switch statement if there is no better way of handling it.

BenArnold

RuntimeException includes more than coding defects. SecurityException?, for example, is a RuntimeException. -- EricHodges


CategoryTime | CategoryException | CategoryJava


EditText of this page (last edited June 11, 2005) or FindPage with title or text search