Avatar ·

Checked and unchecked exceptions in Java: what's the difference and how to use them?

Hi everyone. I started learning Java and can't understand the difference between checked and unchecked exceptions. I read the documentation, but in practice I still get confused. For example, I write a simple method that reads a file: ```java public void readFile(String path) { FileReader file = new FileReader(path); BufferedReader reader = new BufferedReader(file); String line = reader.readLine(); System.out.println(line); } ``` The compiler complains about `FileReader` and `readLine()` — it says I need to handle `FileNotFoundException` and `IOException`. I wrap it in a `try-catch` and it works. But then I write a method that divides numbers: ```java public int divide(int a, int b) { return a / b; } ``` If I pass `b = 0`, the program crashes