• 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

Question about handle and Declare, and PageNo 104

 
Ranch Hand
Posts: 177
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I know only one situation where we have to follow handle and Declare rule for Exceptions.that is when we are rethrowing the same exception (checked) from the catch block as given on page no 365 K&B book.
My question is

Is there any other situation where we have to follow the same rule of "handle and Declare" ?
[ May 08, 2008: Message edited by: sachin verma ]
 
Marshal
Posts: 79179
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Anywhere that you might throw a checked Exception falls into the handle or declare rule.

If you have
  • throw new Throwable();
  • throw new Exception();
  • throw new IOException();
  • throw new AnyOtherNonRuntimeException();
  • or, any call to a method which declares a checked Exception,
  • you are in the realms of handle or declare.
     
    Ranch Hand
    Posts: 147
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Yes, if you are throwing an exception in the catch block.. I believe that is the only scenario where you will need to handle and declare the exception.
     
    sachin verma
    Ranch Hand
    Posts: 177
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Modified Version of Exam watch on page no 104

    Is this not another case of Handle and Declare?

    If not please explain why?


    [ May 08, 2008: Message edited by: sachin verma ]
     
    Ranch Hand
    Posts: 46
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    I believe it's "handle or declare"
     
    reply
      Bookmark Topic Watch Topic
    • New Topic