Exception Class
Java provides a catch-all exception class called Exception
from which all other types of exceptions are derived. This class contains the following methods that are useful when handling exceptions.
Method |
Description |
|
Describes the error in a text message. |
|
Prints the stack trace to the standard error stream. |
|
Returns a description of the exception. This description includes the name of the exception class followed by a colon and the |
Here’s a snippet of code that catches all exceptions and displays the exception’s description on the console:
try
{
// statements that might throw
// an exception
}
catch (Exception e)
{
System.out.println(e.getMessage());
}