Defines an event handler to catch events raised by the application.
<catch
event = "identifiers"
cond= "CDATA"
count = "integer"
/>
Attribute |
Data Type |
Required? |
Default |
Description |
event |
identifiers |
yes |
NA |
Event to handle. Multiple events can be caught in a single catch statement using a space-separated namelist. |
cond |
CDATA |
no |
NA |
Boolean expression that must evaluate to ECMAScript true for the catch to execute. |
count |
integer |
yes |
NA |
Numerical occurrence of the caught event, such as 2 for the second occurrence. This allows you to handle different occurrences of the caught event in different ways. |
A catch contains executable content to run when a specific event is raised. Use the following shorthand elements catch common events:
Element |
Equivalent <catch> Syntax |
<error> |
<catch event="error"> |
<help> |
<catch event="help"> |
<noinput> |
<catch event="noinput"> |
<nomatch> |
<catch event="nomatch"> |
The <catch> element includes two variables in anonymous scope:
_event contains the name of the event that was raised.
_message contains the message accompanying the raised event.
<field>, <form>, <initial>, <menu>, <object>, <record>, <subdialog>, <transfer>, <vxml>
<assign>, <audio>, <clear>, <data>, <disconnect>, <enumerate>, <exit>, <foreach>, <goto>, <if>, <log>, <prompt>, <reprompt>, <return>, <script>, <submit>, <throw>, <value>, <var>
<?xml version="1.0"?>
<vxml version="2.1" xmlns="http://www.w3.org/2001/vxml">
<catch event="terminate">
Caught terminate
<goto next="#formExit"/>
</catch>
<error>
Caught error
<!-- Log the exact error that was caught: -->
<log label="WARN">
The exact error was: <value expr="_event"/>
</log>
<goto next="#formExit"/>
</error>
<var name="bCondition" expr="false"/>
<form id="formEntry">
<!-- A handler for two kinds of event: -->
<catch event="event.foo event.bar">
Form scope event handler
<log label="INFO">
The event thrown was: <value expr="_event"/>.
The message is: <value expr="_message"/>.
</log>
Throwing terminate
<throw event="terminate"/>
</catch>
<catch event="terminate" cond="bCondition">
This handler will not be executed due to the condition
</catch>
<block>
Throwing custom event
<throw event="event.foo" message="Thrown from formEntry"/>
</block>
</form>
<form id="formExit">
<block>
Goodbye
<exit/>
</block>
</form>
</vxml>