• 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
  • Tim Cooke
  • paul wheaton
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

statement not reached

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

why I am getting error statement not reached at return d;
thanks in advance
 
Ranch Hand
Posts: 1157
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Payal,
If you examine the code, there are 2 possibilities that can occur

  1. Exception occurs and the control goes to catch block
  2. There is no exception and try and finally gets executed

  3. In the first case,after executing the println() statement of the catch block, the final block gets executed and then the control comes back to return statement of the catch block.So the statement outside the try..catch..finally doesnot get a chance to execute.
    In the second case, after printing "try" in the try block, the control goes to final block.Here the value of d is initialized and after that the control goes back to the try block which executes the return statement.Again, the return statement outside the try..catch..finally doesn't get a chance to execute.
    The compiler recognizes this fact and hence throws an error that the statement is not reached.
    I have discussed in some other post that you can have one return statememt for every block (i.e. try,catch and finally).However, you need to be careful while having it outside.It will compile only if the compiler sees that there is a possible exit by executing that return statement.
    Hope this helps,
    Sandeep
    SCJP2, OCSD(Oracle JDeveloper), OCED(Oracle Internet Platform)
    [This message has been edited by Desai Sandeep (edited July 26, 2001).]
 
Eliminate 95% of the weeds in your lawn by mowing 3 inches or higher. Then plant tiny ads:
Clean our rivers and oceans from home
https://www.kickstarter.com/projects/paulwheaton/willow-feeders
reply
    Bookmark Topic Watch Topic
  • New Topic