Chapter 7. Exception handling
- [8.3] Describe the advantages of Exception handling. The need for and advantages of exception handlers.
- [8.1] Differentiate among checked exceptions, unchecked exceptions, and Errors. Differences and similarities between checked exceptions, RuntimeExceptions, and Errors. Differences and similarities in the way these exceptions and errors are handled in code.
- [8.2] Create a try-catch block and determine how exceptions alter normal program flow. How to create a try-catch-finally block. Understand the flow of code when the enclosed code throws an exception or error. How to create nested try-catch-finally blocks.
- [8.4] Create and invoke a method that throws an exception. How to create methods that throw exceptions. Rules that cover when overriding or overridden methods throw or don’t throw exceptions. How to determine the flow of control when an invoked method throws an exception. How to apply this to cases when one is thrown without a try block and from a try block (with appropriate and insufficient exception handlers). The difference in calling methods that throw or don’t throw exceptions.
- [8.5] Recognize common exception classes (such as NullPointerException, Arithmetic-Exception, ArrayIndexOutOfBounds-Exception, ClassCastException) How to recognize the code that can throw these exceptions and handle them appropriately.
7.1. Exceptions in Java
7.1.1. A taste of exceptions
7.1.2. Why handle exceptions separately?
7.1.3. Does exception handling offer any other benefits?
7.2. Categories of exceptions
7.2.1. Identifying exception categories
7.2.2. Class hierarchy of exception classes
7.2.3. Checked exceptions
7.2.4. Runtime exceptions
7.2.5. Errors
7.3. Creating a method that throws an exception
7.3.1. Create a method that throws a checked exception
7.3.2. Handle-or-declare rule
7.3.3. Creating a method that throws runtime exceptions or errors
7.3.4. A method can declare to throw all types of exceptions, even if it doesn’t
7.4. What happens when an exception is thrown?
7.4.1. Creating try-catch-finally blocks
7.4.2. Using a method that throws a checked exception
7.4.3. Using a method that throws a runtime exception
7.4.4. Using a method that throws an error
7.4.5. Will a finally block execute even if the catch block defines a return statement?
7.4.6. What happens if both a catch and a finally block define return statements?
7.4.7. What happens if a finally block modifies the value returned from a catch block?
7.4.8. Can a try block be followed only by a finally block?
7.4.9. Does the order of the exceptions caught in the catch blocks matter?
7.4.10. Can I rethrow an exception or the error I catch?
7.4.11. Can I declare my methods to throw a checked exception instead of handling it?
7.4.12. I can create nested loops, so can I create nested try-catch blocks too?
7.4.13. Should I handle errors?