14) Exception Handling
Use try-catch to safely handle runtime errors.
← All Topics
▶ Run Program
Java Code
public class Main { public static void main(String[] args) { try { int x = 5 / 0; } catch (ArithmeticException e) { System.out.println("Cannot divide by zero!"); } } }
Program Input (optional)
Output