If unusual seismic activity is detected in California, you want to notify the authorities immediately. While explicit tests can be done indeed, this is what we are used to it can make for harder code to read. Exceptions provide a uniform way of dealing with such conditions. Exceptions are propagated to the calling method Exceptions are then caught by an encompassing clause in the calling method. All exceptions in Java are subclassed from the Exception base class or one of its subclasses.
Exceptions have two constructors, one with no parameters and one with a string.
Raising an exception Exceptions are raised by a throw statement, which you may or may not see. The throw might be a result of explicitly calling an exception, or because it was thrown by the JVM or a class library you are using. Exceptions thrown by the JVM are also called implicit exceptions. We have encountered this before, in the example of an Array out of bounds. The JVM will throw an exception for you, which will result in a stack trace being printed if you do not handle it.