📄 throw.html
字号:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head> <meta name="generator" content= "HTML Tidy for Linux/x86 (vers 1 September 2005), see www.w3.org"> <title>throw</title> <link href="../cppreference.css" rel="stylesheet" type="text/css"></head><body><table> <tr> <td> <div class="body-content"> <div class="header-box"> <a href="../index.html">cppreference.com</a> > <a href= "index.html">C/C++ Keywords</a> > <a href="throw.html">throw</a> </div> <div class="name-format"> throw </div> <div class="syntax-name-format"> Syntax: </div> <pre class="syntax-box"> try { statement list; } catch( typeA arg ) { statement list; } catch( typeB arg ) { statement list; } ... catch( typeN arg ) { statement list; }</pre> <p>The throw statement is part of the C++ mechanism for exception handling. This statement, together with the <a href= "try.html">try</a> and <a href="catch.html">catch</a> statements, the C++ exception handling system gives programmers an elegant mechanism for error recovery.</p> <p>You will generally use a <a href="try.html">try</a> block to execute potentially error-prone code. Somewhere in this code, a throw statement can be executed, which will cause execution to jump out of the <a href="try.html">try</a> block and into one of the <a href= "catch.html">catch</a> blocks. For example:</p> <pre class="example-code"> try { cout << "Before throwing exception" << endl; throw 42; cout << "Shouldn't ever see this" << endl; } catch( int error ) { cout << "Error: caught exception " << error << endl; } </pre> <div class="related-name-format"> Related topics: </div> <div class="related-content"> <a href="catch.html">catch</a><br> <a href="try.html">try</a> </div> </div> </td> </tr> </table></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -