VoiceXML 2.1 Development GuideHome  |  Frameset Home


<throw>  element

The throw element triggers an event which can be caught and handled by using the catch element. Either platform defined events, such as ‘nomatch’, or user-defined events, such as ‘MyCoolEvent’, may be thrown using this tag. For further information on events and event handling, see Appendix C.


usage
<throw event="NMTOKEN" eventexpr="CDATA" message="CDATA" messageexpr="CDATA">


attributes
eventData Type: NMTOKENDefault: Optional
The event attribute specifies the name of the event to throw to the application. As mentioned, either platform defined events, or user-defined events may be indicated in this attribute. Please note that either event or eventexpr may be used within the throw element, but not both. The event name being thrown is accessible in the catch elements shadow variable _event.
eventexprData Type: CDATADefault: Optional
The eventexpr attribute specifies an ECMAScript expression that evaluates to the event being thrown to the application. As mentioned, either platform defined events, or user-defined events may be indicated in this attribute. Please note that either event or eventexpr may be used within the parent element, but not both.
messageData Type: CDATADefault: Optional
The message attribute allows the developer to include a descriptive message along with the event that is being thrown. The message being thrown is accessible in the catch elements shadow variable _message.
messageexprData Type: CDATADefault: Optional
The messageexpr attribute allows the developer to include an ECMAScript expression resolving to the message being thrown to the application. The messageexpr being thrown is accessible in the catch elements shadow variable _message.



shadow variables
none


parents
<block> <catch> <error> <filled> <help> <if> <nomatch>


children
none


code samples
<Throw event-eventexpr> sample
<?xml version="1.0" encoding="UTF-8"?>

<vxml version = "2.1">

<meta name="author" content="Matthew Henry"/>
<meta name="copyright" content="2005 voxeo corporation"/>
<meta name="maintainer" content="YOUR_EMAIL@HERE.COM"/>

<var name="EventVar" expr="'AnotherUserDefinedEvent'"/>

  <catch event="MyUserDefinedEvent">
    <prompt> we caught the thrown event. </prompt>
    <goto next="#F2"/>
  </catch>

  <catch event="AnotherUserDefinedEvent">
    <prompt> we caught the thrown event expression. </prompt>
  </catch>


<form id="F_1">

  <block>
    <prompt> getting ready to throw an event to be caught. </prompt>
  </block>

  <block>
    <throw event="MyUserDefinedEvent"/>
  </block>
</form>

<form id="F2">

  <block>
  <prompt> now throwing an event expression.</prompt>
    <throw eventexpr="EventVar"/>
  </block>

</form>

</vxml>

<Throw message> sample
<?xml version="1.0" encoding="UTF-8"?>

<vxml version = "2.1">

<meta name="author" content="Matthew Henry"/>
<meta name="copyright" content="2005 voxeo corporation"/>
<meta name="maintainer" content="YOUR_EMAIL@HERE.COM"/>

  <catch event="MyUserDefinedEvent">
    <prompt> <value expr="_message"/>. </prompt>
  </catch>


<form id="F_1">

  <block>
    <prompt> getting ready to throw an event to be caught. </prompt>
    <throw event="MyUserDefinedEvent" message="'here is the thrown message'"/>
  </block>

</form>

</vxml>

<Throw messageexpr> sample
<?xml version="1.0" encoding="UTF-8"?>

<vxml version = "2.1">

<meta name="author" content="Matthew Henry"/>
<meta name="copyright" content="2005 voxeo corporation"/>
<meta name="maintainer" content="YOUR_EMAIL@HERE.COM"/>

  <var name="MyMsg" expr="'here is the thrown message'"/>

  <catch event="MyUserDefinedEvent">
    <prompt> <value expr="_message"/>. </prompt>
  </catch>


<form id="F_1">

  <block>
    <prompt> getting ready to throw an event to be caught. </prompt>
    <throw event="MyUserDefinedEvent" messageexpr="MyMsg"/>
  </block>

</form>

</vxml>



additional links
W3C 2.0 Specification


  ANNOTATIONS: EXISTING POSTS
chuchoomar
5/6/2008 12:49 PM (EDT)
the sistem feels when the user noimput or nomatch automatically?.......so...for instance:



    <field>
        <prompt>Please say a primary color</prompt>
    <grammar type="application/srgs">red | yellow | blue</grammar>
        <nomatch>
            <throw event="event.foo"/>
        </nomatch>
        <catch event="event.foo">
            <audio src="beep.wav"/>
        </catch>
    </field>
</form>
</vxml>


if the user don´t produce a nomatch event the sistem no throw the event nomatch?....and continue with the program ? in fact the sistem jump the nomacth event?......note: is the same with the noimput ? is how if the event was in a conditional?
VoxeoDustin
5/6/2008 12:56 PM (EDT)
Hey,

Correct, the nomatch/noinput containers and their contents will not be executed unless the system detects these events.

Cheers,
Dustin
chuchoomar
5/7/2008 12:43 PM (EDT)

this is possible? o that don´t have .. throw the event in the same event?

<catch event="nomatch" cond="true" count="1">
<throw event"nomatch" message="no has acertado">
<prompt xml:lang="es-es">
<value expr="_message">
</prompt>
</catch>
VoxeoDustin
5/7/2008 3:26 PM (EDT)
Hey,

While this may most likely work, as a best practice, this is a bad idea. A recursive event handler, even with the proper guard conditions, can often cause an infinite loop and should always be avoided. If you need similar functionality, you should throw a separate user defined event within this handler and handle that event separately.

Cheers,
Dustin

login



© 2008 Voxeo Corporation  |  Voxeo IVR  |  VoiceXML & CCXML IVR Developer Site