• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Exception doubt.

 
Ranch Hand
Posts: 180
Netbeans IDE Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why we can't pass Object as parameter in catch(Object o) block like this,as it is the super class Throwable.

 
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Rancher ,

First of all , You should thouroughly think about Exception Handling mechanism .

It is meant for errors and exceptions occured during developing program .

If

You can throw object of any class like String , Integer or your custom class which can not do something special in horrible situataion .
catch block is provided to give you a chance to write some clean up code
if some exception occurs . Exception may or may not happen . It is not
ordinary block .

That is why , It accepts an object of Throwable or its sub type .
These classes provide special functionality to trace and clean up code
in case of exception .
 
Ranch Hand
Posts: 201
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
because it has been coded to accept Throwable or subtypes of Throwable only
 
Ranch Hand
Posts: 3271
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Ashok Pradhan:
Why we can't pass Object as parameter in catch(Object o) block like this,as it is the super class Throwable.



Polymorphism implies that you can use a subclass anywhere a superclass is expected. So, if Throwable is expected, you can use any subclass of Throwable, such as Exception. You can not, however, use a superclass in its place.
 
reply
    Bookmark Topic Watch Topic
  • New Topic