Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Exceptions

 
Jugal Parikh
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello all,

could you tell me the difference between checked exceptions and unchecked exceptions with some examples.i am getting a bit confused between the two.
thank you.
 
Pranav Bhatt
Ranch Hand
Posts: 284
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check this
 
Jugal Parikh
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks pranav but, that did'nt really clear my doubt.
the link you posted had difference between compile time and runtime errors.
 
Nabila Mohammad
Ranch Hand
Posts: 664
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Jugal Parikh:
hello all,

could you tell me the difference between checked exceptions and unchecked exceptions with some examples.i am getting a bit confused between the two.
thank you.



Checked Exceptions are the those Exceptions which the compiler forces you to declared or catch it.
If you dont you ll get a compiler error.
Example of this IOException and all Subclasses of Exception excluding Runtime Exceptions.

Unchecked Exceptions are those Exceptioons which are not required to be caught or handled.
All sublclasses of RuntimeException are unchecked Exceptions like
ClassCastException ,ArrayIndexOutOFBounds,NullPointerException , etc.

Ther is no harm if you declare or handle the exception, though its better not to ,
But you will not get a compiler error for not declaring or handling such Exceptions.

Hope it is clear.
 
Jugal Parikh
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yup it is.thanks Nabila
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic