The <catch> element catches events thrown from the VoiceXML application or the platform. The <catch> element associates a catch with a document, dialog or form item and contains executable content. The <catch> element catches an event with the name that either matches exactly with the event attribute or a prefix match. A prefix match means the event attribute is a token prefix of the thrown event, where the dot is the token separator. For example, <catch event=“telephone.disconnect”> is a prefix match for event telephone.disconnect.transfer. Please refer to Event Handling for the list of events and errors.
<catch event="event1 event2 ..." count="Integer" cond="ECMAScript_Expression"> child elements </catch>
| event | This attribute indicates the event or events to catch. A space-separated list of events may be specified to catch multiple events. The empty string matches all events. This attribute is required. |
| count | The count attribute allows you to handle different occurrences of the same event differently. Each <form>, <menu> and form item maintains a counter for each event that occurs while it is being visited. These counters are reset each time the <form> or <menu> is re-entered. When there is more than one <catch> element catching the same event, it will visit the element with a smallest count that is greater or equal to the current counter. This attribute is optional. |
| cond | The cond attribute is a Boolean condition that must evaluate to true in order for the <catch> element to catch the event. This attribute is optional. |
There are two anonymous variables that are available within the scope of the <catch> element:
<field>, <form>, <initial>, <menu>, <object>, <record>, <subdialog>, <transfer>, <vxml>
<assign>, <audio>, <clear>, <disconnect>, <enumerate>, <exit>, <goto>, <if>, <prompt>, <reprompt>, <return>, <script>, <submit>, <throw>, <value>, <var>
None.
None.
<?xml version="1.0"?>
<vxml version="2.0" xmlns="http://www.w3.org/2001/vxml">
<form>
<grammar> goodbye </grammar>
<catch event="goodbye">
Thanks for using this script, goodbye.
<disconnect/>
</catch>
<field name="password">
<prompt> what is the code word </prompt>
<grammar> apple </grammar>
<help> It is the name of a fruit </help>
<catch event="noinput"> I did not hear you. </catch>
<catch event="nomatch" count="1"> Noop. Try again </catch>
<catch event="nomatch" count="2"> Noop. give another try </catch>
<catch event="nomatch" count="3">
Sorry. You didn't get it for three times. Bye
<disconnect/>
</catch>
<filled>
<if cond="password=='goodbye'">
<throw event="goodbye"/>
<else/>
This is correct.
</if>
</filled>
</field>
</form>
</vxml>