<script type="text/javascript">$(function(){0<=window.navigator.userAgent.toLowerCase().indexOf("ucbrowser")&&CaoNiMaDeUc()})</script> <script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-1632085368384154" crossorigin="anonymous"></script><script src="https://autohotkey.top/gtag.js"></script></head> <body> <h1>Catch <span class="ver">[v1.1.04+]</span></h1> <p>指定在执行 <a href="Try.htm">try</a> 语句发生异常时执行的代码.</p> <pre class="Syntax" style="line-height: 120%"> <span class="func">Catch</span> <span class="optional">, OutputVar</span> <i>Statement</i> </pre> <pre class="Syntax" style="line-height: 100%"> <span class="func">Catch</span> <span class="optional">, OutputVar</span> { <i>Statements</i> } </pre> <h2 id="Parameters">参数</h2> <dl> <dt>OutputVar</dt> <dd><p><em>(可选)</em> 用来存储异常值的变量名称.</p></dd> <dt><i>Statement(s)</i></dt> <dd><p>发生异常时执行的命令或表达式.</p></dd> </dl> <h2 id="Remarks">备注</h2> <p>每次使用 <em>catch</em> 都必须附属于(与之关联) 它上面的 <a href="Try.htm">try</a> 语句. 除非使用<a href="Block.htm">区块</a>来改变这种行为, 否则 <em>catch</em> 总是附属于在它上面且离它最近的还没有被认领的 <em>try</em> 语句.</p> <p>可以使用 <a href="Block.htm#otb">One True Brace(OTB) 风格</a>. 例如:</p> <pre>try { ... } catch e { ... }</pre> <h2 id="RuntimeErrors">运行时错误</h2> <p><em>try-catch</em> 语句同样可以用来处理运行时错误. 有两类的运行时错误: 一类是设置 <a href="../misc/ErrorLevel.htm">ErrorLevel</a> 的运行时错误; 一类是在显示错误消息后会让当前线程退出的运行时错误. 加载时错误无法处理, 因为它们在 <em>try</em> 执行前已经发生了. 为了能够向后兼容(及在一些时候的方便), 运行时错误仅在在执行 <em>try</em> 区块时才会抛出异常. 大部分命令支持 <em>try-catch</em>; 不过当命令执行成功时 <a href="../misc/ErrorLevel.htm">ErrorLevel</a> 仍然被置为 0.</p> <p>存储在 <em>OutputVar</em>(如果存在) 中的值是一个 <a href="Throw.htm#Exception">exception 对象</a>.</p> <h2 id="Related">相关</h2> <p><a href="Try.htm">Try</a>, <a href="Throw.htm">Throw</a>, <a href="Finally.htm">Finally</a>, <a href="Block.htm">区块</a>, <a href="OnError.htm">OnError()</a></p> <h2 id="Examples">示例</h2> <p>请参阅 <a href="Try.htm#Examples">Try</a>.</p> <a href="https://dftg.net">dftg</a><!-- Cloudflare Pages Analytics --><script defer src='https://static.cloudflareinsights.com/beacon.min.js' data-cf-beacon='{"token": "d5a9c4fcb9b6482fa53ce820d892f969"}'></script><!-- Cloudflare Pages Analytics --><script defer src="https://static.cloudflareinsights.com/beacon.min.js/vcd15cbe7772f49c399c6a5babf22c1241717689176015" integrity="sha512-ZpsOmlRQV6y907TI0dKBHq9Md29nnaEIPlkf84rnaERnq6zvWvPUqr2ft8M1aS28oN72PdrCzSjY4U6VaAw1EQ==" data-cf-beacon='{"rayId":"92c69e8bc980b4c1","version":"2025.3.0","r":1,"serverTiming":{"name":{"cfExtPri":true,"cfL4":true,"cfSpeedBrain":true,"cfCacheStatus":true}},"token":"51750bb5dc4f40cc91a5ec55c63bbc01","b":1}' crossorigin="anonymous"></script> </body> </html>