File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes may i know the difference between Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "may i know the difference between " Watch "may i know the difference between " New topic

may i know the difference between

ramesh kothakonda
Ranch Hand

Joined: Feb 14, 2006
Posts: 40
hi all,
we are saying exception is a runtime time error at the time of program execution.

May know the difference between checked exception and unchecked exception. ?

what are examples comes under checked exception and examples comes under unchecked excetion.?

thanking you
with regards

thanking you sir,

The object oriented way of becoming "RICH" is by INHERITANCE<br />Whoever said money can't buy happiness, didn't know where to shop.
Edwin Dalorzo
Ranch Hand

Joined: Dec 31, 2004
Posts: 961
The Java Exceptions Tutorial
Harry Schlong

Joined: Oct 11, 2006
Posts: 2
Checked exceptions are checked at compile time and usually indicate syntax errors, missing libraries, and other structural problems.
Unchecked errors are thrown at runtime and typically indicate logic errors, like getting a null value when there should not be one.
Hence a NullPointerException would be thrown.
Robert Hill
Ranch Hand

Joined: Feb 24, 2006
Posts: 94
Checked exceptions are also thrown at runtime, of course. If an exception is checked that just means that any piece of the code that might throw a checked exception has either a throws in the methods signature or a try/catch around it. Take FileReader for example, the compiler does not check if the file exists(which would be pointless and impossible to check anyway), but makes sure that there is code in place to handle that possibility.

Given that, it is a mystery to me why NumberFormatException isn't checked. Anything that accepts input from an outside source(network, keyboard, file, ect) should be forced to check for error conditions, IMO. and methods that throw NumberFormatException might not directly take input from outside the program, but that is pretty much the only time they are called.
[ October 12, 2006: Message edited by: Robert Hill ]
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
Only the Error and RuntimeException and all of it's subclasses are unchecked exceptions. The NumberFormatException is subclassed from the RuntimeException and therfore it's an unchecked exception. Don't ask why the boys of Sun have put it in there. Also don't ask why NullPointerException is an unchecked exception

All subclasses of Exception, other than RuntimeException, are checked Exceptions. You indeed have to catch them in a try-catch-finally block, or if you don't want to catch them, you have to put it in the throws clause of the corresponding method.
[ October 12, 2006: Message edited by: Bauke Scholtz ]
I agree. Here's the link:
subject: may i know the difference between
jQuery in Action, 3rd edition