SCJP2. Please Indent your code using UBB Code
JavaBeginnersFaq
"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
This method doIt() returns long... but there is no return method
It compiles and runs... I dont get it... I am missing something here ...helpme
SCJP2. Please Indent your code using UBB Code
...
If such an event occurs, then execution of one or more statements may be terminated before all steps of their normal mode of execution have completed; such statements are said to complete abruptly.
An abrupt completion always has an associated reason, which is one of the following:
A break with no label
A break with a given label
A continue with no label
A continue with a given label
A return with no value
A return with a given value
A throw with a given value, including exceptions thrown by the Java virtual machine
The terms "complete normally" and "complete abruptly" also apply to the evaluation of expressions (�15.6). The only reason an expression can complete abruptly is
that an exception is thrown, because of either a throw with a given value (�14.17) or a run-time exception or error (�11, �15.6).
If a statement evaluates an expression, abrupt completion of the expression always causes the immediate abrupt completion of the statement, with the same reason. All
succeeding steps in the normal mode of execution are not performed.
Originally posted by Valentin Crettaz:
Ragu,
a return or throw statement are consider as statement termination regardless whether the method should return a value or not.
From JLS 14.1
In clear, an exception is also capable of returning the ocntrol to the caller method exactly as the return does... If some condition is not met and no value can be returned, then an Exception should be thrown and the caller should take appropriate measures.
HIH
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime. |