wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Checked & Unchecked Exceptions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Checked & Unchecked Exceptions" Watch "Checked & Unchecked Exceptions" New topic
Author

Checked & Unchecked Exceptions

Angela D'souza
Ranch Hand

Joined: Jan 16, 2002
Posts: 469
What is difference between Checked and Unchecked Exceptions???
Thanks,
Angela
Anthony Villanueva
Ranch Hand

Joined: Mar 22, 2002
Posts: 1055
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 ]
Angela D'souza
Ranch Hand

Joined: Jan 16, 2002
Posts: 469
Can I use try/catch for both exception(check & unchecked) or just either of them?
Thanks
Angela
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
Originally posted by Angela D'souza:
Can I use try/catch for both exception(check & unchecked) or just either of them?

Both.


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Checked & Unchecked Exceptions