Handle exceptions or errors using a try-catch block to prevent your program from crashing.
Source Code
try {
int result = 10 / 0;
} catch (ArithmeticException e) {
System.out.println("Cannot divide by zero!");
}
Use try-catch blocks to gracefully handle exceptions and provide informative error messages to the user.