Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Question about handle and Declare, and PageNo 104

 
sachin verma
Ranch Hand
Posts: 177
  • Mark post as helpful
  • send pies
  • 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 ]
 
Campbell Ritchie
Sheriff
Pie
Posts: 49733
69
  • Mark post as helpful
  • send pies
  • 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.
     
    Jart Bo
    Ranch Hand
    Posts: 144
    • Mark post as helpful
    • send pies
    • 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
    • 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 ]
     
    Dumitru Postoronca
    Ranch Hand
    Posts: 46
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    I believe it's "handle or declare"
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic