finally block does not complete normally [message #169915] |
Fri, 23 July 2004 18:06  |
Eclipse User |
|
|
|
Hi,
I upgraded to Eclipse 3.0 this week and am now getting a problem warning
on all of my finally blocks in all my projects. When I check to see what
Eclipse suggests for to fix this, I get "No corrections available". As
fas as I know there is nothing wrong with my finally blocks. I've done an
internet and Eclipse search and found nothing. Is anyone else getting
these errors? Does anyone know why they're being generated? Maybe it's a
bug in Eclispe?
Thanks in advance,
Shelli
|
|
|
|
|
|
Re: finally block does not complete normally [message #170077 is a reply to message #169933] |
Mon, 26 July 2004 16:17   |
Eclipse User |
|
|
|
Aha!
Yes, all the finally blocks that are getting the warning have the return
statement in them. I'll have to take a closer look and make sure there's
no potential for hidden bugs and make changes as necessary.
Thank you so much!
Shelli
Olivier Thomann wrote:
> Le Fri, 23 Jul 2004 22:06:29 +0000 (UTC), shelli.orton@wmode.com
> (Shelli) a écrit :
> >I upgraded to Eclipse 3.0 this week and am now getting a problem warning
> >on all of my finally blocks in all my projects. When I check to see what
> >Eclipse suggests for to fix this, I get "No corrections available". As
> >fas as I know there is nothing wrong with my finally blocks. I've done an
> >internet and Eclipse search and found nothing. Is anyone else getting
> >these errors? Does anyone know why they're being generated? Maybe it's a
> >bug in Eclispe?
> Your finally block might contain a return statement. If this is the
> case, the finally block doesn't complete normally. Normally means that
> you exit the block at the end of the block without going through a
> return or a throw statement.
> Paste one of your finally block and we can tell you for sure what is
> wrong.
> Because a finally block is executed even if there is an uncaught
> exception in the try block, a finally block that doesn't complete
> normally is a potential problem or source of bugs.
> For example, if you have something like this:
> class Example {
> static void foo() {
> throw new RuntimeException();
> }
> public static void main(String[] args) {
> try {
> foo();
> } finally {
> return;
> }
> }
> }
> Do you think that the exception will be thrown after the finally block
> is executed? The answer is no. Because you have a return statement,
> the runtime exception is "eaten".
> That example will throw the runtime exception:
> class Example {
> static void foo() {
> throw new RuntimeException();
> }
> public static void main(String[] args) {
> try {
> foo();
> } finally {
> }
> }
> }
> This is why we have such warning. Note this is only a warning. There
> is nothing wrong doing that. It could however hide a bug.
> Hope this help,
> --
> Olivier
|
|
|
|
|
Re: finally block does not complete normally [message #170278 is a reply to message #170255] |
Tue, 27 July 2004 10:28  |
Eclipse User |
|
|
|
Originally posted by: olivier_thomannNO.ca.ibm.comSPAM
Le Tue, 27 Jul 2004 13:45:07 +0200, "Robert Klemme" <bob.news@gmx.net>
a écrit :
>I prefer to put the return into the try block. Why? Because you then get
>soon warned that you forgot to handle exceptions properly if you do:
Sure. My point was simply to say that a return statement in a finally
block might have undesired side effects :-).
--
Olivier
|
|
|
Powered by
FUDForum. Page generated in 0.04219 seconds