by Dinesh Thakur Category: Exception Handling

Based on the severity of the error, Exception classes are categorized into two groups: unchecked exceptions and checked exceptions. Unchecked exceptions are those that can be either handled or ignored. If the programmer ignores an unchecked exception, the program will terminate when such an error occurs. On the other hand, if a handler is provided for an unchecked exception, the result of the occurrence of such an error will depend on the code written in the exception handler. An example of an unchecked exception is the class RuntimeException (and its sub-classes), which is a sub-class of the class Exception. It is a very important class in Java programming.

Checked exceptions are a type of exceptions that cannot be ignored. These exception classes represent routine abnormal conditions. The programmer should anticipate and catch them to avoid abnormal termination of the program. These exceptions are checked for by the compiler and thus the program code must handle or declare checked exceptions, otherwise the program will not compile. Thus, checked exceptions should be treated more carefully.

All exceptions instantiated from the Exception class, or from sub-classes of Exception except RuntimeException and its sub-classes, must be dealt with in one of the following ways:

• They must be handled with a try block followed by a catch block, or

• they must be declared in the throws clause of any method that can throw them.

About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.SC (Computer Science), MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.

Search Content