Exception Class
Package: java.lang
Java provides a catchall exception class called Exception that all other types of exceptions are derived from. This class contains the methods that are useful when handling exceptions.
Constructors
|
Constructor |
Description |
|
|
Creates a new |
|
|
Creates a new |
Methods
|
Method |
Description |
|
|
Describes the error in a text message. |
|
|
Prints the stack trace to the standard error stream. (The stack trace lists all the threads and objects that are active when the exception occurs.) |
|
|
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());
}
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access