|
![]() |
Blob b = new Blob();
Error e = ci.m(); if (e.status == Error.ok) { ... }
void m(args, Error error) { ... } ci.m(..., e) if (e.status != Error.ok) { ... }
ci.m(); if (error.status != Error.ok) { ... }
int main () { ci.f() } int f() { ci.g() } int g() { if (b) ci.g() }
main()
is called, and e()
calls f()
.
f()
then calls g()
.
f()
and g()
return.
main()
returns and the program ends.
throw
statement throws exceptions.
try
block delimits exception handling.
catch
block catches exceptions.
throw
Statementthrow
statement signals (throws, raises) an exception:
throw
exception-ref;
return
in syntax and semantics.
throw new NullPointerException(); final NullPointerException e = new NullPointerException(); throw e;
catch
Blockcatch (
ex-type ex-name) {
body}
catch (ExceptionType e) { // blah blah blah }
try
Blocktry {
body}
try { body } catch ( ex-type ex-name ) { body } catch ( ex-type ex-name ) { body } // and so on
|
|
catch
body,
continue after the try-catch statement.
|
|
Throwable
AncestorThrowable
class is the top of the exception
hierarchy.
Throwable(String message, Throwable cause) Throwable(String message) Throwable(Throwable cause) Throwable()
Error
ClassThrowable
child Error
defines abnormal
conditions.
Error
children include VirtualMachineError
and AssertionError
.
Exception
ClassThrowable
child Exception
defines
undesirable conditions the application should handle.
Exception
is a useful catch-all in a catch block.
Exception
descendants.
Exception
ChildrenException
child IOException
defines
undesirable conditions related to input-output operations.
FileNotFoundException
and
EOFException
.
Exception
child RuntimeException
defines
undesirable conditions related to non-I/O execution.
ClassCastExcepton
and
NullPointerException
.
throws
Clausethrows ex [ , ex ]...
String read() throws IOException { ... }
@throws
tag.
try { // state set-up ci.g() // state tear-down } catch (...) { ... } catch (...) { ... }
ci.g()
's exception interrupts state tear-down.
finally
Blocksfinally { code }
is always executed, exception or not, exception handled or not.
try { // state set-up ci.g() } catch (...) { ... } catch (...) { ... } finally { // state tear-down }
|
|
|
none | handled | propagated |