• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Exceptions

 
Trader Joey
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1. all exceptions are subclasses of .Throwable class.
2. Exceptions of the Exception subclass may be handled in a try/catch block.
3. Exceptions of the Error subclass should never be handled.
4. if a method does not handle an exception it must be declared in the throws clause. the exception declared in the throws clause may be any exception which is a subclass of Exception but not of RuntimeException.
Are all the points mentioned above correct ???
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
IMO, all the points are valid except 2nd.
2nd should be "Exceptions of Exceptions can be handled in try/catch block except 'Runtime Exceptions'.
Please correct me if I'm wrong.
Prabhu.
 
Indy
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Exception subclass only contains checked exceptions, unincluding Runtime exceptions. so 2) should be true, right?
Indy
 
Suresh
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi nikhil,
Runtime exceptions can also be put in the throws clause, but it is not of any use, since they are implicitly included!! So, you won't get any compile time/ runtime error, even if you put it in the throws clause.
I tried this program:

It works the same way, even if you remove the throws clause of the divide method definition.
Hope it's of some use
Regards,
suresh.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic