1 Java Training | Java Exceptions | Java Exception Types Mon Oct 03, 2011 4:18 pm
aquanetta
Java Training | Java Exceptions | Java Exception Types
Java Exceptions:
A Java exception is an object that describes an error condition occurred in the code.
When an exception occurs, an object representing that exception is created and thrown in the method that caused the exception.
That method may choose to handle the exception itself, or pass it on.
At some point, the exception is caught and processed.
Exception Types:
All exception types are subclasses of class Throwable.
The two subclasses of Throwable are Error and Exception.
There are two types of exceptions in class Exception:
1. Checked exceptions – When you call a method that throws a checked exception, you must tell the compiler what you are going to do about the exception if it is ever thrown.
2. Unchecked exceptions – The compiler does not require you to keep track of unchecked exceptions.
A subclass of Exception is RuntimeException.
Exceptions belonging to the subclasses of RuntimeException are unchecked expections.
All other subclasses of the class Exception are checked.
Exceptions of the type Error are caused by Java run-time environment
OutofMemoryError is an example of type Error.
Checked exceptions are due to external circumstances that the programmer cannot prevent. The compiler checks that your program handles these exceptions.
Unchecked exceptions are programmers’ fault.
Java Exceptions:
A Java exception is an object that describes an error condition occurred in the code.
When an exception occurs, an object representing that exception is created and thrown in the method that caused the exception.
That method may choose to handle the exception itself, or pass it on.
At some point, the exception is caught and processed.
Exception Types:
All exception types are subclasses of class Throwable.
The two subclasses of Throwable are Error and Exception.
There are two types of exceptions in class Exception:
1. Checked exceptions – When you call a method that throws a checked exception, you must tell the compiler what you are going to do about the exception if it is ever thrown.
2. Unchecked exceptions – The compiler does not require you to keep track of unchecked exceptions.
A subclass of Exception is RuntimeException.
Exceptions belonging to the subclasses of RuntimeException are unchecked expections.
All other subclasses of the class Exception are checked.
Exceptions of the type Error are caused by Java run-time environment
OutofMemoryError is an example of type Error.
Checked exceptions are due to external circumstances that the programmer cannot prevent. The compiler checks that your program handles these exceptions.
Unchecked exceptions are programmers’ fault.