Where Do Exceptions Come from?
Moving away from the more-pragmatic approach we have followed in this chapter, it is now time to put things into perspective and understand where things come from in the larger schema of the Java API. Exceptions, as mentioned in a previous section, hang from the Throwable
class, which is part of the java.lang
package. They are on the same level as errors (which we explained earlier). In other words, both Exception
and Error
are subclasses of Throwable
.
Only object instances of the Throwable
class can be thrown by the Java throw
statement; therefore, the way we had to define our own exception implied using this class as a point of departure. As stated in the Java documentation for the Throwable
class, this includes a snapshot of the execution stack at the time of creation. This allows you to look for the source of the exception (or the error) because it includes the state of computer memory at that time. A throwable object can contain the reason for...