wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) 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 Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "checked & unchecked exceptions..." Watch "checked & unchecked exceptions..." New topic
Author

checked & unchecked exceptions...

pal kandy
Greenhorn

Joined: Jan 17, 2002
Posts: 9
somebody please help me understand the difference between checked exceptions & unchecked exceptions. why checked exceptions only need be declared in a java program & not the runtime exceptions?
any input will be appreciated
regards
nitin
Valentin Crettaz
Gold Digger
Sheriff

Joined: Aug 26, 2001
Posts: 7610
pal k,
The following discussions might be helpful:
http://www.coderanch.com/t/237185/java-programmer-SCJP/certification/Checked-Exception
http://www.coderanch.com/t/193763/java-programmer-SCJP/certification/Unchecked-Checked-Exceptions
http://www.coderanch.com/t/208417/java-programmer-SCJP/certification/checked-unchecked-exceptions
I got those links by running a search in this forum with the keywords "checked unchecked", I got 88 results!!
Moreover, I'd like you to read the Javaranch Naming Policy and change your publicly displayed name to comply with our unique rule. Thank you.
[ April 12, 2002: Message edited by: Valentin Crettaz ]

SCJP 5, SCJD, SCBCD, SCWCD, SCDJWS, IBM XML
[Blog] [Blogroll] [My Reviews] My Linked In
Mag Hoehme
Ranch Hand

Joined: Apr 07, 2002
Posts: 194
Maybe this helps:
I think of checked exceptions as exceptions that are somehow expected. E.g. when opening a file, the file may not exist. In this case, the program should offer some alternative.
Likewise I take unchecked exceptions as bugs and should be avoided programmatically.


Mag
Valentin Crettaz
Gold Digger
Sheriff

Joined: Aug 26, 2001
Posts: 7610
Hmmmm, an unchecked exception is not really a bug in my opinion. Take the following example. You ask the user to fill in some integer value so that you can perform the following operation 10/user_value. Now if the user provides a 0, the expression is going to throw an ArithmeticException. It is not really a bug, you could either catch that exception and inform the user that 0 is not acceptable or you can develop a input parser that verifies that the user does not enter 0 in the first place. Either way is valid.
Runtime exception are exception whose cause is difficult to prove at compile-time...
(JLS 11.2.2 Why Runtime Exceptions are Not Checked)
Mag Hoehme
Ranch Hand

Joined: Apr 07, 2002
Posts: 194
Yeah, that's true. And a good explanation in JLS.
Thank you.
pal kandy
Greenhorn

Joined: Jan 17, 2002
Posts: 9
hi valentine,
i've changed my publicly displayed name.
thanx to u & mag for the clarifications.
still the difference is vague after my reading the JLS also.
wht JLS says is ---
This compile-time checking for the presence of exception handlers is designed to reduce the number of exceptions which are not properly handled.(abt chkd exceptions)
The information available to a compiler, and the level of analysis the compiler performs, are usually not sufficient to establish that such run-time exceptions cannot occur, even though this may be obvious to the programmer. Requiring such exception classes to be declared would simply be an irritation to programmers.(abt unchkd exceptions)
my question is if language implementers wanted to allow programmers to handle exceptional situations
by means of handler code, then why the runtime exceptions shud not be also declared in the method definitions & handled by code as the case of chkd exceptions, bcos the possibility of occurrence of chkd exceptions is same as that of runtime exceptions.
Regards
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: checked & unchecked exceptions...
 
Similar Threads
checked and Unchecked exceptions
Regarding Overiding
Exceptions
Questions from mock Exam !!!
Exceptions