What is the difference between a runtime exception and a plain exception?Runtime Exceptions like out-of-bound array indices, NullPointerException , AirthmeticException are all subclasses of java.lang.RuntimeException class, which is a subclass of Exception class. They are known as unchecked exceptions, meaning that the programmer have no need to make a method for catching these exceptions. If they are not caught explicitly it is dealt by the default exception handler.
The exceptions other than RuntimeException all exceptions are called checked exceptions. The compiler ensures that if a method can throw a checked exception, directly or indirectly, then the method must explicitly deal with it. The method must catch the exception and take appropriate action.
|