When compiling my application, I am getting this warning msg:
---------
warning: finally clause cannot complete normally
---------
I get this warning once for every finally clause in my code.
What does this mean? What can I do to fix this?
You're doing something that you shouldn't do in your finally clauses.
If you post an example of code that does this, we could offer more help.
"Completing normally" is a technical term in the Java Language
Specification. It means finishing a block of code because you run into
the end of it and have no more code to run. A block of code can also
complete ABNORMALLY by:
1. Encountering a return, break, or continue statement.
2. Throwing an exception that isn't handled within that block.
Finally blocks should generally be able to complete normally. Although
the language specification doesn't require it, it just makes sense.
Hence the warning. As an example, you might write this:
try
{
doSomeIO();
}
finally
{
cleanup();
return;
}
The problem is that the return statement prevents the finally block from
completing normally. If doSomeIO() throws an exception, that exception
will be completely lost without a trace. That's because when a finally
block completes abnormally, any exceptions are lost and the program
continues in whatever way the finally block told it to. In this case,
that means returning from a method, NOT throwing whatever exception got
you to the finally block in the first place.
There is some debate about whether a finally block should EVER complete
abnormally in case of a second error, for example. However, ever
finally block should complete normally at least as the main case,
possibly with exceptions being thrown in the oddball cases.
--
www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.
Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation