• 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

how to differentiate exceptions

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
how can we differentiate exceptions that
where we have to write it
1. in front of throws clause
2. or in try catch block

pease help me how
 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
According to whatever i've learnt , an exception can either be declared or catched...both the ways make no difference but implementing one is a must.

Pooja
 
Ranch Hand
Posts: 2412
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Either approach is fine except that if you place an exception in the throws clause of the method, then any method that calls it must also take care of the exception.

Of course this is provided the method is not inherited from a superclass or superinterface. In that case, you are only allowed to list subclasses of the exceptions listed in the superclass or superinterface. In that case you either have to use a try-catch block or wrap a checked exception in an unchecked exception and throw it.
 
Ranch Hand
Posts: 1272
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can always differentiate exception types using the instanceof operator.
 
reply
    Bookmark Topic Watch Topic
  • New Topic