Java Exceptions  «Prev  Next»

Lesson 12

Java Exceptions Review - Classes, Checked, Unchecked Exceptions

In this module, you learned about exceptions. You had a chance to explore the keywords:
  1. catch
  2. throw
  3. throws
  4. finally
This module discussed Java's Exception classes, checked and unchecked exceptions, and how to catch and throw exceptions in your own programs.

Java's Exception mechanism helps in the following ways.
  1. It allows the creation of new exceptions that are custom to a particular application domain.
  2. It improves code because error handling code is clearly separated from the main program logic.

  1. You can define your own exceptions based of your application business domain.
    For example, in a banking application, you might want to create an InsufficientFundsException. This increases code clarity as compared to having a single (or a few standard) exception classes.
  2. The error handling logic is put in the catch block, which makes the main flow of the program clean and easy to understand.
  3. Exception handling improves the code because the code does not have to include error handling code if it is not capable of handling it. Exception handling can propagate the exception up the chain so that it can be handled somewhere at a more appropriate place.
  4. The Java language will enable you to create new exceptions tailored for your application.