Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
Exceptions are a way of describing exceptional circumstances within a program. They are a way of signaling that something unexpected (exceptional) has happened. For that reason, exceptions are efficient at interrupting the current flow of the program and signaling that there is something that requires attention. As such, programs that judiciously use exceptions benefit from a better control flow and become more robust. Even so, using exceptions indiscriminately can cause performance degradation.
Within Java, exceptions are said to be thrown and caught. Throwing an exception involves telling the code that you have encountered an exception and involves using the throw keyword to signal the JVM to find any code capable of handling this exceptional circumstance within the current stack. Catching an exception involves telling the compiler which exceptions you can handle, and on which part of the code you want to monitor for these exceptions occurring. This is denoted by the try/catch Java syntax (described in recipe 6-1)