This week's book giveaway is in the Artificial Intelligence and Machine Learning forum.
We're giving away four copies of Machine Learning with R: Expert techniques for predictive modeling and have Brett Lantz on-line!
See this thread for details.
Win a copy of Machine Learning with R: Expert techniques for predictive modeling this week in the Artificial Intelligence and Machine Learning forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar

finally clause cannot complete normally ???

 
Ranch Hand
Posts: 443
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Why is the following code giving out a warning message "finally clause cannot complete normally" when compiled?
 
town drunk
( and author)
Posts: 4118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Because you're returning two values: a 0, and then a 1.
M
 
Ranch Hand
Posts: 348
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The code compiles & returns 0 on my system (I am using 1.4.1)
PS : no warning message either.
[ August 22, 2003: Message edited by: chi Lin ]
 
Ranch Hand
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mine too.. But Alton is mentioning a warning message. I don't get any warning even when I use JBuilder.
 
Alton Hernandez
Ranch Hand
Posts: 443
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, it will compile, but it will also gives out a warning message:


Sample14.java:17: warning: finally clause cannot complete normally
}
^
1 warning


Here's my version of Java(it's on Linux):


java version "1.4.2"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2-b28)
Java HotSpot(TM) Client VM (build 1.4.2-b28, mixed mode)


Actually, I was wondering if the message is inline with the JLS.
[ August 22, 2003: Message edited by: Alton Hernandez ]
 
Andres Gonzalez
Ranch Hand
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
are you using any IDE? mine is (win 2k):
java version "1.4.1_02"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1_02-b06)
Java HotSpot(TM) Client VM (build 1.4.1_02-b06, mixed mode)
[ August 22, 2003: Message edited by: Andres Gonzalez ]
 
Alton Hernandez
Ranch Hand
Posts: 443
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Andres,
I am not using any IDE, it's all command line.
 
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No problem here. Compiles and prints 0 as expected. Powerbook G4 Titanium, Mac OS 10.2.6
java version "1.4.1_01"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1_01-39)
Java HotSpot(TM) Client VM (build 1.4.1_01-14, mixed mode)
---BW
 
Alton Hernandez
Ranch Hand
Posts: 443
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
Thanks for all your reply.
It's probably due to my version (1.4.2). I noticed that most of you are using 1.4.1.
But I wonder why the change?
 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ya mine is 1.4.2:-
and the warning is there
FinallyCode.java:11: warning: finally clause cannot complete normally
}
^
1 warning
Output completed (6 sec consumed) - Normal Termination
 
Ranch Hand
Posts: 1392
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
http://developer.java.sun.com/developer/bugParade/bugs/4842426.html
Bug Id 4842426
Votes 1
Synopsis RFE: try-catch-finally compiler message request
Category java:compiler
Reported Against 1.4.1
Release Fixed
State Closed, duplicate of 4814715
Related Bugs
Submit Date Apr 03, 2003
A DESCRIPTION OF THE REQUEST :
java version "1.4.1_01"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1_01-b01)
Java HotSpot(TM) Client VM (build 1.4.1_01-b01, mixed mode)
If a try block has a return statement and a finally block is added with a
return statement, the first return statement is ignored/unused.
JUSTIFICATION :
The compiler should warn or error and tell coders that the first return
statement is unreachable.
 
Andres Gonzalez
Ranch Hand
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for the link!
 
Alton Hernandez
Ranch Hand
Posts: 443
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Marlene.
But I think the right link that properly describes my problem is this one.
Actually, looking at the original link, I don't know why they complained about this as a problem:


If a try block has a return statement and a finally block is added with a
return statement, the first return statement is ignored/unused.


The problem described in the bug report IS the expected behaviour, as written in the book The Java Programming Language 3rd Edition pp 206 by Arnold, Gosling and Holmes:


A finally clause is always entered with a reason. That reason may be that the try code finished normally, that it executed a control flow statement such as return, or that an exception was thrown in code executed in the try block. The reason is remembered when the finally clause exits by falling out the bottom. However, if the finally block creates its own reason to leave by executing a control flow statement(such as break or return) or by throwing exception, that reason supersedes the original one, and the reason is forgotten.


[ August 24, 2003: Message edited by: Alton Hernandez ]
 
Marlene Miller
Ranch Hand
Posts: 1392
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There seem to be several similar bug reports.
Here is another one, http://developer.java.sun.com/developer/bugParade/bugs/4908268.html
And here is one from 1997, where the author wants a warning.
http://developer.java.sun.com/developer/bugParade/bugs/4088715.html
But the JLS goes out of its way to explain that what happens in a finally block can disrupt whatever happened in the try block.
I agree with you Alton. I don't know why they complained.
Thank you Karan for comfirming that problem occurs in 1.4.2. That was my clue to look in the bug database.
 
This looks like a job for .... legal tender! It says so right in this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!