Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

doubt in Exception

 
Divya Gehlot
Ranch Hand
Posts: 243
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am really confused with checked and unchecked exceptions every time I read and get confused with that. Is there any simple way or trick to check checked and unchecked exceptions from exam point of view(SCJP1.5).
Thanks in Advance.
 
Sundaram Karthick
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Unchecked exceptions are subclasses of RuntimeException, and are usually implemented using IllegalArgumentException, NullPointerException, or IllegalStateException.
Checked are subclasses of Exception.
It is somewhat confusing, but note as well that RuntimeException (unchecked) is itself a subclass of Exception (checked).
 
Divya Gehlot
Ranch Hand
Posts: 243
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
I am confused in that. Sometimes in questions they will ask whether it is Runtime Exception or ......
So so how to get overcome from all these . please suggest me some trick and tips.
 
Nik Arora
Ranch Hand
Posts: 652
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Divya,
Refer thisLink and if you have doubts post it here.


Regards
Nik
Scjp 1.5
 
Chandra Bhatt
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Simple rules:

1- Checked exceptions: Compiler doesn't excuse you. You must handle
or declare the exception if your code is supposed to throw any checked
exception as java.io.FileNotFoundException, java.io.IOException etc.
All checked exceptions extend from java.lang.Exception

Unchecked Exception: Where compiler doesn't bother regarding handle
or declare rule. All unchecked exception classes extend from
java.lang.RuntimeException


Isn't it simple?

Note: java.lang.RuntimeException also extend java.lang.Exception

Thanks,
 
chintan ramavat
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think recalling the Exception Tree from

Throwable
||
1 Error 2 Exception
- AssertionError ||
Runtime Compiletime
(unchecked) (checked)
| |
no need to need to play round
play around
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic