🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.jbuilder.java.api
2 messages
2 total messages Started by Kang Wed, 04 May 2005 02:12
missing return statement
#97
Author: Kang
Date: Wed, 04 May 2005 02:12
30 lines
1689 bytes
I think the method1 and the method2 is the same.
Why the compiler complains "missing return statement" in the method2?
Thanks.

public class ExceptionHandlingTest {
    public static void main(String[] args) throws Exception {
            System.out.println(method1());
    }
    public static String method1() throws Exception{
        try{
            return "method1";
        }catch(Exception e){
            throw new Exception();
        }finally{

        }
    }
    public static String method2() throws Exception{
        try{
            return "method2";
        }catch(Exception e){
            method3();
        }finally{

        }
    }
    public static void method3() throws Exception{
        throw new Exception();
    }
}
Re: missing return statement
#98
Author: Kevin Dean [TeamB]
Date: Wed, 04 May 2005 02:59
24 lines
1796 bytes
Kang wrote:

> I think the method1 and the method2 is the same.
> Why the compiler complains "missing return statement" in the method2?
> Thanks.

In order for the compiler to prove definitively that the two are
equivalent, it would have to inline method3, and inline any methods it
calls, and so on, and so on.  All the compiler sees when its compiling
method2 is a call to method3; it doesn't know or care at that point
exactly what method3 does.

-- 
Kevin Dean [TeamB]
Dolphin Data Development Ltd.
http://www.datadevelopment.com/

NEW WHITEPAPERS
Team Development with JBuilder and Borland Enterprise Server
Securing Borland Enterprise Server
http://www.datadevelopment.com/papers/index.html

Please see Borland's newsgroup guidelines at
http://info.borland.com/newsgroups/guide.html
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads