Lesson 10 of 10
Exception Handling
Exceptions are errors that occur during program execution. Use try/catch to handle them gracefully. Use finally for code that always runs. You can also throw your own exceptions with throw.
JAVA
public class Main {
public static void main(String[] args) {
try {
int result = 10 / 0;
} catch (ArithmeticException e) {
System.out.println("Cannot divide by zero!");
} finally {
System.out.println("Cleanup done.");
}
}
}