Java: Exceptions - More

Exceptions | Exception Usage | Exceptions - More

Kinds of Exceptions

There are many exceptions, but they can be put into two groups: checked exceptions and unchecked exceptions. There is some controversy about which type you should use. A discussion of some of the issues can be found at Java theory and practice: The exceptions debate.

Exception hierarchy

[Not yet written]

Multiple catch clauses

[Not yet written]

Order of catch clauses

[Not yet written]

Printing the stack trace

[Not yet written]

Throwing exceptions

[Not yet written]

Danger from the intermediate layers - finally

Exceptions provide a good infrastructure for error processing. The simplicity of throwing an exception at a deep level and catching it at a high level may generate problems at the intermediate, skipped, levels. Did any of these methods leave any part of a data structure or resource in an inconsistent state? Each place that this may be true of needs to enclose critical code in a try...finally block.

Define libarary exceptions to tell programmer they should fix their code

If you write a library that is used by others, throw your own execeptions if your code is called with illegal values, eg, something isn't initialized. Your exceptions are a way to tell the applications programmer that they should fix their code.

Defining your own exceptions

You can also create your own exceptions. [Not yet written]