JDK 1.4 provides a couple of powerful new Exceptions features -- chained exceptions and StackTraceElements.
Chained exceptions formalize the idea that one exception can trigger another. In this e-doc, you'll learn how they work, what they replace, and how to traverse a chain of exceptions.
StackTraceElements provide programmatic interface to stack traces, which are generated as part of an exception. This is a good deal more convenient than generating a stack trace dump and parsing the output. In this e-doc, you'll learn how to access and use StackTraceElements. You'll also learn how to create a StackTraceElement, and you'll learn when this is appropriate to do.
This e-doc will show you how to:
- Interpret chained exceptions
- Traverse an exception chain
- Create an exception chain
- Access and view StackTraceElements
- Synthesize StackTraceElements
Sample programs included in this chapter:
- A custom stack-trace dumper that shows the source code context for each line of the exception
- A task system which executes tasks in a thread pool and synthesizes correct exceptions for exceptions within the pool