aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Exceptions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Exceptions" Watch "Exceptions" New topic
Author

Exceptions

Venkata Saraswathi
Ranch Hand

Joined: Sep 27, 2008
Posts: 55
I read there are two types of Exceptions one is checked(subtype of Runtime Exception) caused by program errors, and another is unchecked which are caused by resource unavailability (not by program errors).

How can we distingusih an exception is of type checked/unchecked exception by looking at it's functionality without looking at its hierarchy.

For ex. for following Exceptions how can we distinguish without looking at Exception heirarchy.
NullPointerException,
NumberFormatException.

Thanks,
--Venkata.
Venkata Saraswathi
Ranch Hand

Joined: Sep 27, 2008
Posts: 55
Thanks!

--
Venkata
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18141
    
  39

I read there are two types of Exceptions one is checked(subtype of Runtime Exception) caused by program errors, and another is unchecked which are caused by resource unavailability (not by program errors).


Actually, you may have gotten it backwards. The unchecked exceptions are the ones that is a RuntimeException (or subtype of). And the checked exceptions are exceptions which are *not* RuntimeExceptions.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Venkata Saraswathi
Ranch Hand

Joined: Sep 27, 2008
Posts: 55
Yes, It's my mistaque.

Actually I am looking answer for this question.


How can we distingusih an Exception is of type checked/unchecked exception by looking at it's functionality without looking at its hierarchy.
For ex. for following Exceptions how can we distinguish without looking at Exception heirarchy.
NullPointerException,
NumberFormatException

[ September 28, 2008: Message edited by: Venkata Saraswathi ]
Manju Kavi
Ranch Hand

Joined: Sep 25, 2008
Posts: 33
Hi,
Well, unchecked exceptions are there because of bad programming, or in other words they are completely under our control(programmer). Its a bad programming style to handle unchecked exceptions, we need to spend time on correcting these errors. Compiler wont check handlers for these exceptions. For example exceptions like NullPointerException, ArrayIndexOutofBoundExceptio etc..

Where as checked exceptions are unpredictable and compiler will check for handlers to handle these exceptions. So the compiler can tell you wheather the exception is checked or unchecked.
V. Potluri
Ranch Hand

Joined: Mar 29, 2007
Posts: 36
Hi,

Whether it is checked exception or unchecked exception, it will be raised during execution of program.

Unchecked exception may raise because of logical problems. But certain exceptions are raised because of environmental problems. For example: in case of I/O operations with file, there is a chance that file may be moved to some other location / may not be accessable. Program fails to execute because of these problems which are not because of program code. So compiler will take extra care, what extra efforts we have taken in order to handle the environmental problems. That is why certain exceptions are checked by compiler at compile time. Because those exceptions which are checked by compiler are known as checked exceptions.

ex: IOException and it's sub classes.

Regards,
Gopal.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Exceptions
 
Similar Threads
Exceptions -- checked versus unchecked.... and which ones are which
Exceptions thrown in interfaces and their implementations
exceptions
Runtime Exception
How to recognise a checked or unchecked exception