Lecture 2
Lecture 2
Lecture 2
Exceptions
Outline
• Why exceptions?
• Java error handling mechanism
• Checked & unchecked exceptions
• Working with exceptions
• Design issues
References
If a procedure might throw a checked exception, Java requires that If a procedure might throw an unchecked exception, unchecked
the exception be listed in the procedure’s header; otherwise, there exceptions need not be listed in the header.
will be a compile-time error.
If code calls a procedure that might throw a checked exception, Java If code calls a procedure that might throw a unchecked exception,
requires that it handles the exception; otherwise, there will be a unchecked exceptions need not be handled in the calling code
compile-time error.
Checked exceptions are subtype of Exception class Unchecked exceptions are subtype of RuntimeException class
Handle an exception