 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Kang Guest
|
Posted: Wed May 04, 2005 2:12 am Post subject: missing return statement |
|
|
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();
}
}
|
|
| Back to top |
|
 |
Kevin Dean [TeamB] Guest
|
Posted: Wed May 04, 2005 2:59 am Post subject: Re: missing return statement |
|
|
Kang wrote:
| Quote: | 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
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|