java - how to use finally -
I did not understand the use of the statement at all. Can anyone tell me what is the difference between:
try {a; Block; Close; Statement; } Hold (exception e) {handles; exception; E } Finally {do}; some; cleanliness; }
On the one hand:
Try {a; Block; Close; Statement; } Hold (exception e) {handles; exception; E } Tax; some; cleanliness;
Other
They are different if
-
Try
-black is completed by throwing ajava.lang.Throwable
which is notjava.lang.Exception
For example, because it is ajava.lang.Error
asAssertionError
orOutOfMemoryError
. - Try-block completes a sudden control flow statement like
continue
,break
orreturn
- Use of any tedious, or control flow descriptions)
More commonly, the Java language guarantees that the block is executed before the completion of the tentmember statement . (Note that if attempt-statement is not complete, then there is no guarantee about ultimately one statement can not be completed due to various reasons including hardware shutdown, OS shutdown, VM lock (for example, system's Cause) Exit
), thread wait ( threads suspend ()
, synchronize
, Object.wait ()
, Thread .leep ()
) or otherwise busy (endless loops, ,,,).
So, a ultimately
block is a better place for clean-up actions. The method can not guarantee cleanup exeuction from the end of the body, but in itself, still.
Comments
Post a Comment