Java: handling exceptions

Example:

int x = 10;
int y = 0;
int result = x / y;
This code throws an ArithmeticException.

Solution:

try {
    int result = x / y;
} catch (ArithmeticException e) {
    System.out.println("Division by zero is not allowed!");
}

Beginner's Guide to Java