Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Why return is not forced by complier when method throws Throws Exception

 
Ganesh Gowtham
Ranch Hand
Posts: 225
IBM DB2 Eclipse IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,



In the above code why Why return is not forced by complier when method throws Throws Exception

i mean complier forces me to write return p ;
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24212
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The only time that the compiler will insist you add a return statement is if control reaches the end of a non-void method. That never happens here: before the method gets to the end, you throw an exception, which leaves the method, so no return is needed since it would never happen, anyway.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic