with Certified Solutions
What is the primary purpose of exception handling in Java?
✔✔ To manage runtime errors and maintain normal program flow
How do you declare a try-catch block in Java?
✔✔ By using `try { } catch(Exception e) { }`
What happens if an exception is not caught in a Java program?
✔✔ The program terminates and prints a stack trace
Which keyword is used to define a custom exception in Java?
✔✔ `throw`
What is the difference between checked and unchecked exceptions?
✔✔ Checked exceptions must be handled or declared, while unchecked exceptions do not
require explicit handling
1
, Which Java class is the parent of all exceptions?
✔✔ `Throwable`
How can you ensure that a block of code always executes, regardless of whether an exception
occurs?
✔✔ By using a `finally` block
What is the purpose of the `throws` keyword in a method signature?
✔✔ It declares exceptions that a method might throw
How do you create a user-defined exception in Java?
✔✔ By extending the `Exception` class
What is an `ArithmeticException` in Java?
✔✔ An exception that occurs when an illegal arithmetic operation, like division by zero, is
performed
What does the `getMessage()` method do in an exception object?
2