Exceptions handling
Objectives
Applied
- Given a method that throws one or more exceptions, code a method that calls that method and catches the exceptions.
- Given a method that throws one or more exceptions, code a method that calls that method and throws the exceptions.
- Code a method that throws an exception.
- Use the methods of the Throwable class to get information about an exception.
- Code a class that defines a new exception, and then use that exception in an application.
- Use an assert statement in an application to make an assertion about a condition.
- Given Java code that uses any of the language elements presented in this chapter, explain what each statement does.
Knowledge
- Describe the Throwable hierarchy and the classes that are derived from it.
- Describe the difference between checked and unchecked exceptions and explain when you need to catch each.
- Explain how Java uses the stack trace to determine what exception handler to use when an exception occurs.
- Describe the order in which you code the catch clauses in a try statement.
- Explain what it means to swallow an exception.
- Explain when the code in the finally clause of a try statement is executed and how that compares to code that follows a try statement.
- Describe three situations where you might want to throw an exception from a method.
- Describe two situations where you might create a custom exception class.
- Explain what exception chaining is and when you might use it.
- Explain what assertions are and how you can use them in your applications.