Exceptions

An exception is an object that signals a runtime error and interrupts the normal flow. You handle it with try / catch / finally and raise it with throw. Checked exceptions (Exception) must be declared or handled; unchecked ones (RuntimeException) do not require it. Do not swallow them silently.

Example

try {
    Integer.parseInt(texte);
} catch (NumberFormatException e) {
    System.out.println("Invalid number");
}

Related concepts

The whole glossary