1

Is this statement/example valid for checked and unchecked exception?

Unchecked Exception: The exceptions that are not checked at compile time are called unchecked exceptions. Example:

 public class UncheckedException {

    public static void main(String[] args) {

            int value = 10/0;
        }
    }

Checked Exception: The exceptions that are checked at compile time are called Checked exceptions. Example:

public class CheckedException {

    public static void main(String[] args) {

        try {
                int value = 10/0;
            } catch (Exception e) {
                System.out.println("Caught " + e);
            }

        }
    }
1
  • Please describe your question clearly Commented May 10, 2015 at 7:43

1 Answer 1

4

No it is not a valid example / illustration. In both cases the exception that is thrown is an unchecked exception.

The difference between checked exceptions and unchecked exceptions is the exception class.

  • ArithmeticException is always an unchecked exception because it extends RuntimeException

  • IOException is a checked exception because it does not extend RuntimeException (or Error).

The fact that you do or don't catch the exception doesn't change its nature.


At the risk of repeating myself:

Unchecked Exception: The exceptions that are not checked at compile time are called unchecked exceptions.

Checked Exception: The exceptions that are checked at compile time are called Checked exceptions.

These are both incorrect definitions.


See also: Java: checked vs unchecked exception explanation

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.