• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Checked & Unchecked Exceptions

 
Angela D'souza
Ranch Hand
Posts: 469
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is difference between Checked and Unchecked Exceptions???
Thanks,
Angela
 
Anthony Villanueva
Ranch Hand
Posts: 1055
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 469
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can I use try/catch for both exception(check & unchecked) or just either of them?
Thanks
Angela
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Angela D'souza:
Can I use try/catch for both exception(check & unchecked) or just either of them?

Both.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic