Checked and unchecked exceptions
If you look up the documentation of the java.lang
package API, you will discover that the package contains almost three dozen exception classes and a couple of dozen error classes. Both groups extend the java.lang.Throwable
class, inherit all the methods from it, and do not add other methods. The methods that are most often used in the java.lang.Throwable
class include the following:
void printStackTrace()
: This outputs the stack trace (stack frames) of the method calls.StackTraceElement[] getStackTrace()
: This returns the same information asprintStackTrace()
but allows programmatic access of any frame of the stack trace.String getMessage()
: This retrieves the message that often contains a user-friendly explanation of the reason for the exception or error.Throwable getCause()
: This retrieves an optional object ofjava.lang.Throwable
that was the original reason for the exception (but the author of the code decided to wrap it...