• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

Exceptions

 
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks!

--
Venkata
 
author
Posts: 23959
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Venkata Saraswathi
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic