Loading
Java - Types of Exception-interview

Q1. What is the difference between Exception and Error in Java?

Exception represents conditions a program should handle, while Error represents serious problems (like OutOfMemoryError) that are usually not recoverable.






Q2. How do checked and unchecked exceptions differ in terms of compiler checking?

Checked exceptions must be either caught or declared using throws, while unchecked exceptions don’t require explicit handling.






Q3. Why does Java differentiate between checked and unchecked exceptions?

To enforce compile-time error handling for predictable issues (like file I/O), while allowing flexibility for runtime programming errors (like NullPointerException).






Q4. Can a custom exception be checked or unchecked? How?

Yes. Extend Exception (for checked) or RuntimeException (for unchecked).






Q5. What happens if a checked exception is not handled in code?

The compiler throws an error, forcing the developer to handle it using try-catch or declare it in the method signature with throws.