This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
A checked Exception is an Exception that a method is obliged to deal with, either in catching it and fixing the screwup in a try-catch block, or rethrowing it to the calling method, or even both. Either way, explicit contingency measures have been taken (correctly or otherwise ) in case of an error. These are the sort of Exceptions that the poor programmer simply has no control over: a file goes missing, a class fails to get loaded, you know, "I-can't-get-blamed-for-this" errors . An unchecked Exception is either a RuntimeException or an Error; basically, RuntimeExceptions are Exceptions which are due more to logic errors or design flaws. Think of NullPointerException or ArrayIndexOutOfBoundsException, and you will get an idea of what I mean. A method is not forced by the compiler at gunpoint to deal with these exceptions. If thrown, it will be passed, or propagated to the calling method, which in turn deals with it by actively catching it (if there were such contingencies declared) or passively rethrowing it up the method activation stack. (The method activation stack is the JVM's way of knowing which method called what, and after a method gets finished, to where it will return.) If main() doesn't deal with it, it goes to the default exception handler, who kills the process and prints out a not-so-friendly stack trace. -anthony [ April 05, 2002: Message edited by: Anthony Villanueva ]
Joined: Jan 16, 2002
Can I use try/catch for both exception(check & unchecked) or just either of them? Thanks Angela