VoiceXML 2.1 Development Guide Home  |  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

event Data Type: NMTOKEN Default: 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.
eventexpr Data Type: CDATA Default: 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.
message Data Type: CDATA Default: 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.
messageexpr Data Type: CDATA Default: 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
kakeakeai
6/8/2010 4:45 PM (EDT)
How would i catch an event thrown in a vxml document that was initiated by a ccxml document in the ccxml document. (transition?)
jdyer
6/8/2010 5:57 PM (EDT)
Hello,

If you wish to send an event from the VoiceXML context to the CCXML context you would want to leverage our CCXML.send API ( [url=http://docs.voxeo.com/ccxml/1.0-final/sendevent_ccxml10.htm?search=events#anchor]here[/url] ). You could catch said event int he VoiceXML context, use [url=http://docs.voxeo.com/voicexml/2.0/data.htm]<data>[/url] to perform the HTTP request to the CCXML session, which should achieve your desired functionality. I do hope this helps, and if there are any other questions please let us know, as our team is most certainly standing by to be of service!

Regards,

John Dyer
Customer Engineer
Voxeo Support

[color=blue][b]***** Visit us June 21st-23rd for the Voxeo Customer Summit! *****[/b][/color]
[url=http://www.voxeo.com/summit2010]Register Here[/url]

login



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