aspose file tools*
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: 24166
    
  30

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 agree. Here's the link: http://aspose.com/file-tools
 
subject: Why return is not forced by complier when method throws Throws Exception
 
Similar Threads
Understanding Exception Hierarchy
Exceptions
Use of comparator and comparable interface
problem when trying code from HFSJ
Question on throw, throws and try/catch