This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes Java in General and the fly likes Why return is not forced by complier when method throws Throws Exception Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Java in General
Bookmark "Why return is not forced by complier when method throws Throws Exception " Watch "Why return is not forced by complier when method throws Throws Exception " New topic
Author

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

Ganesh Gowtham
Ranch Hand

Joined: Mar 30, 2005
Posts: 225

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 ;


Thanks, Ganesh Gowtham
http://ganesh.gowtham.googlepages.com
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24189
    
  34

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.


[Jess in Action][AskingGoodQuestions]
 
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
 
subject: Why return is not forced by complier when method throws Throws Exception
 
It's not a secret anymore!