|Navigate Exceptions topic: )|
The ideal time to catch an error is at compile time, before you even try to run the program. However, not all errors can be detected at compile time. The rest of the problems must be handled at run time through some formality that allows the originator of the error to pass appropriate information to a recipient who will know how to handle the difficulty properly.
Improved error recovery is one of the most powerful ways that you can increase the robustness of your code. Error recovery is a fundamental concern for every program you write, but it's especially important in Java, where one of the primary goals is to create program components for others to use. To create a robust system, each component must be robust. By providing a consistent error-reporting model using exceptions, Java allows components to reliably communicate problems to client code.
In Java, there are two main flows of code executions.
catchblock begins. If that is not found at the current method level the search continues at the caller method level, until a matching
catchblock is found. If none is found the exception will be handled by the JVM, and usually the java program terminates.
catch"matching" block is found, that block will be executed, the exception object is passed to the block as a parameter. Then normal program execution continues after the
catchblock. See Java exception handling syntax.
catchblock. Exception object encapsulates the information about the error's location and its nature. All Exception objects must be inherited from the
java.lang.Throwable. See the UML diagram below.
catchkeyword and specifying the exception object's class or its super-class.
CustomerNotFoundExceptionmay indicate that a customer was not found.
Manage research, learning and skills at defaultlogic.com. Create an account using LinkedIn to manage and organize your omni-channel knowledge. defaultlogic.com is like a shopping cart for information -- helping you to save, discuss and share.