<catch>
Defines an event handler within the current scope. The <catch> element detects events of the specified type and executes code when they are generated.
The following three JavaScript variables are accessible within the <catch> element:
- _event—Specifies the name of the event that was caught.
- _exception (Nuance extension)—Specifies the exception that caused the event to be generated.
- _message—Specifies a message that describes the event that was caught.
VoiceXML includes several elements that serve as shorthand for catching certain events: an error (see <error>), a request for help (see <help>), no input from the user (see <noinput>), or a result rejected by the interpreter (see <nomatch>).
Attributes
This section describes the attributes you can set for this element.
Name |
Data type |
Default |
---|---|---|
CDATA |
optional |
|
CDATA |
optional |
|
NMTOKENS |
optional |
cond
The cond attribute specifies an ECMA expression. This ECMA expression must evaluate to the Boolean TRUE before the <catch> element is available for selection within the Form Interpretation Algorithm (FIA).
count
The count attribute (default is 1) specifies the minimum number of specified event occurrences that must take place before the handler is available for selection in the Form Interpretation Algorithm (FIA). The handler with the highest count value is selected for execution. The count attribute thus allows different occurrences of the same event to be handled differently.
Each <clear>, <form> and <menu> element, as well as each form item, maintains a counter for each event that occurs while it is being visited.
Form-level and menu-level event counters are not reset by the <clear> element, but rather each time the <menu> or <form> is re-entered. The form-level counters are used in the selection of an event handler for events thrown in a form-level <filled> element.
Form items are reset every time the related <form> is re-entered, and can also be reset with the <clear> element. An item's event counters are not reset when the item is re-entered without leaving the <form>.
Note: Counters are incremented against the full event name, and also every prefix matching the event name. For example, an occurrence of the event "event.foo.1" increments the counters associated with handlers for "event.foo.1", "event.foo", and "event".
event
The event attribute specifies the prefix name of the Event types to handle. This value may be an empty string or unspecified, indicating that all events are to be caught. This value may also be a space-separated list of events, indicating that the <catch> element catches all the events named in the list.
For example:
<catch event="noinput nomatch">
In such a case, a separate event counter (see count attribute) is maintained for each event.
Exceptions originating from Java can be caught by prefixing the exception with error.semantic, for example:
<catch event =
"error.semantic.vcommerce.so.MaxErrorsExceededException">
<audio expr="prompt_location
+'maxerrorsexceptionaftermain.wav'"/>
<goto expr="main_menu"/>
</catch>
In the previous example, the <catch> element catches the MaxErrorsExceededException event.
Children
- Parsed character data
- <assign>
- <audio>
- <clear>
- <data>
- <disconnect>
- <enumerate>
- <exit>
- <foreach>
- <goto>
- <if>
- <log>
- <prompt>
- <reprompt>
- <return>
- <script>
- <nuance:send>
- <submit>
- <nuance:taskbegin>
- <nuance:taskend>
- <throw>
- <value>
- <var>
Parents
Sample code
<form id="monty_python_holy_grail">
<field name="your_name">
<prompt>What is your name?</prompt>
<help>
<prompt>hint: you are the king.</prompt>
<reprompt/>
</help>
</field>
<field name="swallow">
<prompt>What is the average wind speed velocity of an unladen swallow?</prompt>
<catch event="help">
<prompt>hint: it depends where the bird comes from.</prompt>
<reprompt/>
</catch>
</field>
<noinput>
<prompt>sorry, i didn't catch that.</prompt>
<reprompt/>
</noinput>
<nomatch>
<prompt>no, sorry, that's not it. try again.</prompt>
</nomatch>
<error>
<log expr="'Error processing bridge sequence. and now
for something completely different.../>
<throw event="SOMETHING_COMPLETELY_DIFFERENT"/>
</error>
<filled>You may pass.</filled>
</form>
A <catch> handler uses JavaScript variables as follows:
<catch event="error">
<if expr="_event == 'error.badfetch'">
<goto next="nextpage.vxml"/>
</if>
Ending session due to <value expr="_event"/>
with message <value expr="_message"/>
<exit namelist="_event _message _exception"/>
</catch>