Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Exceptions

 
Venkata Saraswathi
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Thanks!

--
Venkata
 
Henry Wong
author
Marshal
Pie
Posts: 20880
75
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • 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
  • 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 ]
 
Manju Kavi
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • 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.
 
V. Potluri
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic