Checked vs Unchecked

This lesson introduces the type of exceptions.

We'll cover the following...

Question # 1

What are the different types or kinds of exceptions?

There are two categories of exceptions in Java:

  • Checked Exceptions

  • Unchecked Exceptions

Question # 2

What are checked exceptions?

These are exceptional conditions that a well-written application should anticipate and recover from. Checked exceptions are subject to catch-or-specify requirement. Let's understand this requirement with an example. Say you write the following utility method print(), which prints a passed in string. But you want to throw an exception if the passed in string is null. The code appears below:

    void print(String str) throws Exception {
        if (str == null)
            throw new Exception("");

        System.out.println(str);
    }
...