<doc>
  <legacy_id>2322</legacy_id>
  <name>throw</name>
  <type>control structure</type>
  <syntax>
    <example>throw <i>errorString</i></example>
  </syntax>
  <library></library>
  <objects>
  </objects>
  <synonyms>
  </synonyms>
  <classification>
    <category>Writing LiveCode</category>
  </classification>
  <references>
    <keyword tag="catch">catch Keyword</keyword>
    <control_st tag="return">return Control Structure</control_st>
    <control_st tag="try">try Control Structure</control_st>
  </references>
  <history>
    <introduced version="1.0">Added.</introduced>
  </history>
  <platforms>
    <mac/>
    <windows/>
    <linux/>
    <ios/>
    <android/>
  </platforms>
  <classes>
    <desktop/>
    <server/>
    <web/>
    <mobile/>
  </classes>
  <security>
  </security>
  <summary><glossary tag="return">Returns</glossary> an error message to a<keyword tag="$"> control structure</keyword>.</summary>
  <examples>
    <example>open file tFile for text read</example>
    <example>if the result is not empty then<p>  throw "failed_to_open_file"</p>end if</example>
  </examples>
  <description>
    <p>Use the <b>throw</b> <glossary tag="control structure">control structure</glossary> in a <glossary tag="handler">handler</glossary> <glossary tag="call">called</glossary> from within a <control_st tag="try">try</control_st> <glossary tag="control structure">control structure</glossary>.</p><p/><p><b>Form:</b></p><p>The <b>throw</b> <glossary tag="statement">statement</glossary> appears on a line by itself, anywhere inside a <glossary tag="handler">handler</glossary>.</p><p/><p><b>Parameters:</b></p><p>The <i>errorString</i> is the <keyword tag="string">string</keyword> that is <glossary tag="return">returned</glossary> to the <glossary tag="call">calling</glossary> <control_st tag="try">try</control_st> <glossary tag="control structure">control structure</glossary>. The <i>errorString</i> becomes the <glossary tag="parameter">parameter</glossary> of the <keyword tag="catch">catch</keyword> lin in the <control_st tag="try">try</control_st> <glossary tag="control structure">control structure</glossary>.</p><p/><p><b>Comments:</b></p><p>If LiveCode generates the error (for example, an execution error from a built-in command), it returns a positive number to the <b>try</b> <glossary tag="control structure">control structure</glossary>. To avoid confusion, therefore, a <b>throw</b> <glossary tag="control structure">control structure</glossary> should return a <glossary tag="negative">negative</glossary> number, or a non-numeric <keyword tag="string">string</keyword>.</p><p/><p>If a <b>throw</b> <glossary tag="control structure">control structure</glossary> is <glossary tag="execute">executed</glossary> in a <glossary tag="handler">handler</glossary> that was not <glossary tag="call">called</glossary> from within a <control_st tag="try">try</control_st> <glossary tag="control structure">control structure</glossary>, an <message tag="errorDialog">errorDialog</message> <keyword tag="message box">message</keyword> is sent to the <glossary tag="object">object</glossary>, and the <i>errorString</i> is passed as a <glossary tag="parameter">parameter</glossary>.</p><p/><p><b>Note:</b> The <b>throw</b> <glossary tag="control structure">control structure</glossary> is implemented internally as a <glossary tag="command">command</glossary> and appears in the <function tag="commandNames">commandNames</function>.</p>
  </description>
</doc>