|
|||||
|
|||||
Related Syntax | Related Concepts | ||||
control structure |
catch |
Syntax
catch catch-parameter*
You can use catch
to mark the point in your program where execution
will resume following a throw
. A catch
has a name, so you can have
multiple active catch
clauses with different names. Each throw
must name the
catch
it throws to. A catch
clause introduces a block of code which is
executed once the throw
is caught.
In addition to the catch
es you declare yourself, you can also catch
two predefined OmniMark throw
s: #program-error
and
#external-exception
.
A catch
is active only when it is in the current execution scope of
your program. OmniMark will look for the catch
named in a throw
in the
current scope. If the named catch
does not exist in the current scope,
OmniMark looks for it in the parent scope, and so on. Once the named
catch
is found, OmniMark closes the current scope and all intervening
scopes as required to reach the catch
. Execution is then transferred
to the block of code following the catch
clause.
If the named catch
is not found, OmniMark raises an error which will
be caught by the first available catch
of #program-error
.
It is a compile-time error to use a catch
that has not been
declared.
You can catch
the same catch
name at different points in your program,
but there can be only one catch
of a particular catch
name in any one
lexical scope. Only the catch
in the innermost execution scope is
active at any given point in program execution.
Many OmniMark constructs can result in a rule or function being called
recursively. Therefore, a single catch
clause may exist at many
different levels of execution scope when a program is run.
catch
clauses are always at the end of a scope. That is to say, a
catch
clause is outside the normal flow of that scope. Execution does
not fall through into a catch
clause. The code in a catch
clause can
only be executed as a result of a throw
to that catch
. A throw
initiated inside a catch
clause or an associated always
clause cannot
be caught in the same local scope. throw
s within a catch
or always
clause must be caught at a wider scope of execution.
Related Syntax |
Related Concepts |
Copyright © Stilo International plc, 1988-2010.