Exception Handling Strategies
- Exception Handling Strategies
- Exception Handling Strategy - Overview
- Exception Handling Requirements
- Application Survival
- Notifying Relevant Parties
- Error Diagnostics and Reproduction
- Separation of Abstraction Layers
- More Readable and Maintainable Code
- Error Location and Context
- Error Causes, Types and Reactions
- Strategy Elements
- Error Detection
- Error Information Gathering
- Throwing Exceptions
- Propagating Exceptions
- Catching Exceptions
- An Exception Handling Strategy Template
- An Exception Class Template
- Throwing the AppException
- Propagating the AppException
- The ErrorInfo List
- Catching the AppException
- Avoid Exception Hierarchies
Throwing Exceptions
Jakob Jenkov |
Throwing exception is the next step after error detection and information gathering. When you detect an error, you need to determine if you need to throw an exception, and what information to include in that exception.
What information to embed in the exception is determined in the previous stage - Error Information Gathering
Here is a simple example:
String errorId = ... String errorDescription = ... String contextId = .... throw new MyException(errorId, errorDescription, contextId);
Later in this tutorial trail I will show you an Exception class definition that is much better suited to address the requirements listed earlier in this trail.
Next: Propagating Exceptions
Tweet | |
Jakob Jenkov |