Alexey Loubyansky [
https://community.jboss.org/people/aloubyansky] created the document:
"try-catch-finally control flow"
To view the document, visit:
https://community.jboss.org/docs/DOC-18731
--------------------------------------------------------------
The CLI implements a simplified analogue of Java's try-catch-finally control flow. It
consists of three sets of operations and commands (with each set being a batch)
corresponding to the try, catch and finally blocks. Both catch and finally blocks are
optional but at least one of them should be present. Unlike in Java, only one catch block
can be specified.
The control flow begins with execution of the try batch. If the try batch finished
successfully (i.e. the outcome of the operation was success), then the catch batch is
skipped and the finally batch is executed. If the try batch failed (i.e. the outcome of
the operation was failure, in case of, e.g., a +java.io.IOException+ the whole
try-catch-finally control flow will terminate immediately) then the catch batch (if it is
present) will be executed. The finally batch (if it is present) will always execute at the
end of the control flow no matter whether the try and catch batches succeeded or failed to
execute.
There are four commands that define the try-catch-finally control flow: *try*, *catch*,
*finally* and *end-try*.
*try* command starts the try batch. The try batch continues until one of *catch* or
*finally* command is met.
*catch* command marks the end of the try batch (the try batch is then held back) and
starts the catch batch.
*finally* command marks the end of the catch batch (if the current batch is a catch batch)
or the try batch (if the catch batch was not specified) and starts the finally batch.
*end-try* is the command that ends either catch or finally batch (depending on which one
was the last one) and runs the try-catch-finally control flow.
Here is an example that either creates or re-creates a datasource and enables it:
try
/subsystem=datasources/data-source=myds:add(connection-url=xxx,jndi-name=java:/myds,driver-name=h2)
catch
/subsystem=datasources/data-source=myds:remove
/subsystem=datasources/data-source=myds:add(connection-url=xxx,jndi-name=java:/myds,driver-name=h2)
finally
/subsystem=datasources/data-source=myds:enable
end-try
--------------------------------------------------------------
Comment by going to Community
[
https://community.jboss.org/docs/DOC-18731]
Create a new document in JBoss AS 7 Development at Community
[
https://community.jboss.org/choose-container!input.jspa?contentType=102&a...]