CodeStudy.net
Toggle Menu
Home
Online Java Compiler
Tutorials
Java Tutorial
Python Tutorial
SQL Database Design
Blog
All Posts
Exception Handling in Java
Check how well you handle errors and exceptions in Java programs.
1. Which of the following is an example of an unchecked exception in Java?
IOException
SQLException
NullPointerException
ClassNotFoundException
2. Which components are part of exception handling in Java?
try
catch
throw
finalize
3. Checked exceptions must be handled or declared in the method signature.
True
False
4. What keyword is used to declare that a method might throw a checked exception?
5. Which block ensures resources are closed automatically after use?
try-catch
try-finally
try-with-resources
catch-finally
6. Which of the following are checked exceptions?
IOException
RuntimeException
SQLException
ArithmeticException
7. A try block can exist without a catch or finally block.
True
False
8. What is the parent class of all exceptions in Java?
9. What is the output of: try { int x = 10/0; } catch (ArithmeticException e) { System.out.print("Error"); } finally { System.out.println("Done"); }
Error
Done
ErrorDone
Compile error
10. Which statements about the finally block are true?
Executes even if there's a return in the try block
Executes only if an exception is thrown
Used to release resources (e.g., closing files)
A try block can have multiple finally blocks
11. Custom unchecked exceptions typically extend RuntimeException.
True
False
12. What keyword is used to explicitly throw an exception object?
13. Which exception is thrown by Integer.parseInt("abc")?
NumberFormatException
IllegalArgumentException
ParseException
IOException
14. Which are true about try-with-resources?
Resources must implement AutoCloseable
Resources close in reverse declaration order
Replaces finally for resource cleanup
Only one resource can be declared
15. What happens when an exception is not caught by any catch block?
Program continues execution
The thread terminates
Exception is ignored
JVM restarts
Reset
Answered 0 of 0 — 0 correct