A break exits the enclosing statement.
BreakStatement:
break;
break Identifier ;
break exits the innermost enclosing while, for, do, or switch statement, resuming execution at the statement following it.
If break is followed by Identifier, the Identifier must be the label of an enclosing while, for, do or switch statement, and that statement is exited. It is an error if there is no such statement.
Any intervening finally clauses are executed, and any intervening synchronization objects are released.
Note: If a finally clause executes a return, throw, or goto out of the finally clause, the break target is never reached.
Return Statement
A return exits the current function and supplies its return value.
ReturnStatement:
return;
return Expression ;
Expression is required if the function specifies a return type that is not void. The Expression is implicitly converted to the function return type.
At least one return statement is required if the function specifies a return type that is not void.
Expression is illegal if the function specifies a void return type.
Before the function actually returns, any enclosing finally clauses are executed, and any enclosing synchronization objects are released.
The function will not return if any enclosing finally clause does a return, goto or throw that exits the finally clause.
If there is an out postcondition (see design by contract), that postcondition is executed after the Expression is evaluated and before the function actually returns.
Goto Statement
A goto transfers to the statement labelled with Identifier.
GotoStatement:
goto Identifier ;
Any intervening finally clauses are executed, along with releasing any intervening synchronization mutexes.
It is illegal for a goto to be used to skip initializations.
With Statement
The with statement is a way to simplify repeated references to the same object.
WithStatement:
with ( Expression ) BlockStatement
with ( TemplateInstance ) BlockStatement
where Expression evaluates to an Object reference. Within the with body the referenced Object is searched first for identifier symbols. The with statement
with (expression)
{
...
ident;
}
is semantically equivalent to:
{
Object tmp;
tmp = expression;
...
tmp.ident;
}
Note that expression only gets evaluated once. The with statement does not change what this or super refer to.
Synchronize Statement
The synchronize statement wraps a statement with critical section to synchronize access among multiple threads.
SynchronizeStatement:
synchronized Statement
synchronized ( Expression ) Statement
synchronized allows only one thread at a time to execute Statement.
synchronized (Expression), where Expression evaluates to an Object reference, allows only one thread at a time to use that Object to execute the Statement.
The synchronization gets released even if Statement terminates with an exception, goto, or return.
Example:
synchronized { ... }
This implements a standard critical section.
Try Statement
Exception handling is done with the try-catch-finally statement.
TryStatement:
try BlockStatement Catches
try BlockStatement Catches finally BlockStatement
try BlockStatement finally BlockStatement
Catches:
LastCatch
Catch
Catch Catches
LastCatch:
catch BlockStatement
Catch:
catch ( Parameter ) BlockStatement
Parameter declares a variable v of type T, where T is Object or derived from Object. v is initialized by the throw expression if T is of the same type or a base class of the throw expression. The catch clause will be executed if the exception object is of type T or derived from T.
If just type T is given and no variable v, then the catch clause is still executed.
It is an error if any Catch Parameter type T1 hides a subsequent Catch with type T2, i.e. it is an error if T1 is the same type as or a base class of T2.
LastCatch catches all exceptions.
Throw an exception.
ThrowStatement:
throw Expression ;
Expression is evaluated and must be an Object reference. The Object reference is thrown as an exception.
Volatile Statement
Do not cache values across volatile statement boundaries.
VolatileStatement:
volatile Statement
Statement is evaluated, and no common subexpressions or memory references cached in registers are propagated either into it or out of it. This is useful for accessing memory that can change asynchronously, such as memory mapped I/O or memory accessed by multiple threads.
A volatile statement does not guarantee atomicity. For that, use synchronized statements.
Share with your friends: |