Java Exception Handling Basics: Checked & Unchecked Exceptions

🚀 Starting My Java Learning Journey – Day 13 ♦Topic: Exception Handling in Java Exception Handling is used to handle runtime errors so that the program does not crash abruptly. It helps in maintaining the normal flow of the program. ✅ Types of Exceptions 1)Checked Exceptions → Checked at compile time 2) Unchecked Exceptions → Occur at runtime ✅ Keywords Used in Exception Handling ✔ try → block where code is written ✔ catch → handles the exception ✔ finally → always executes (optional) ✔ throw → used to explicitly throw an exception ✔ throws → declares exceptions ✅ Example Program public class Main { public static void main(String[] args) { try { int result = 10 / 0; // may cause exception System.out.println(result); } catch (ArithmeticException e) { System.out.println("Cannot divide by zero"); } finally { System.out.println("Execution completed"); } } } Output: Cannot divide by zero Execution completed 💡 Key Points: ✔ Prevents program crash ✔ Helps handle runtime errors ✔ Improves program reliability #Java #JavaLearning #Programming #BackendDevelopment #CodingJourney #ExceptionHandling

To view or add a comment, sign in

Explore content categories