Terms you'll need to understand:
Techniques you'll need to master:
In this chapter, you review how to handle exceptions. Java has two types of runtime errors: errors and exceptions. An error originates from the Java Virtual Machine (JVM) and indicates an imminent crash. An exception originates from the code and indicates an exceptional circumstance that needs to be handled by a try-catch-finally block. Only if an exception is not handled does the application crash. Remember that you can't recover from an error that causes your application to crash. You can, however, recover from an exception with proper use of the try-catch-finally construction. When adding exception handling to your certification solution, you should bear in mind the higher concept of problem resolution in software. Approaching exception handling first from this higher ground eases the burden of quality control later. In other words, there are steps you can take to reduce bugs during the design phase. Figure 17.1 illustrates the relationship between different types of errors in Java. Note that all errors and exceptions in Java are subclasses of the Throwable class. The primary characteristic is whether Java checks for that type of error. Figure 17.1. The Throwable class hierarchy.
The following list describes the characteristics of errors and exceptions and explains the differences between them:
The preceding list describes the code- related errors you must be aware of. However, there are other types of problems that software engineers must contend with in addition to errors and exceptions. The next section discusses these problems from a broader perspective. |