<bdo id='gnbUm'></bdo><ul id='gnbUm'></ul>
  1. <small id='gnbUm'></small><noframes id='gnbUm'>

    <legend id='gnbUm'><style id='gnbUm'><dir id='gnbUm'><q id='gnbUm'></q></dir></style></legend>
    <tfoot id='gnbUm'></tfoot>
  2. <i id='gnbUm'><tr id='gnbUm'><dt id='gnbUm'><q id='gnbUm'><span id='gnbUm'><b id='gnbUm'><form id='gnbUm'><ins id='gnbUm'></ins><ul id='gnbUm'></ul><sub id='gnbUm'></sub></form><legend id='gnbUm'></legend><bdo id='gnbUm'><pre id='gnbUm'><center id='gnbUm'></center></pre></bdo></b><th id='gnbUm'></th></span></q></dt></tr></i><div id='gnbUm'><tfoot id='gnbUm'></tfoot><dl id='gnbUm'><fieldset id='gnbUm'></fieldset></dl></div>
    1. 如果投掷会发生什么;语句是在 catch 块之外执行

      时间:2023-10-06
    2. <i id='FLLEY'><tr id='FLLEY'><dt id='FLLEY'><q id='FLLEY'><span id='FLLEY'><b id='FLLEY'><form id='FLLEY'><ins id='FLLEY'></ins><ul id='FLLEY'></ul><sub id='FLLEY'></sub></form><legend id='FLLEY'></legend><bdo id='FLLEY'><pre id='FLLEY'><center id='FLLEY'></center></pre></bdo></b><th id='FLLEY'></th></span></q></dt></tr></i><div id='FLLEY'><tfoot id='FLLEY'></tfoot><dl id='FLLEY'><fieldset id='FLLEY'></fieldset></dl></div>

            • <bdo id='FLLEY'></bdo><ul id='FLLEY'></ul>

              <small id='FLLEY'></small><noframes id='FLLEY'>

                <tbody id='FLLEY'></tbody>

              • <legend id='FLLEY'><style id='FLLEY'><dir id='FLLEY'><q id='FLLEY'></q></dir></style></legend>
                <tfoot id='FLLEY'></tfoot>
                本文介绍了如果投掷会发生什么;语句是在 catch 块之外执行的吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                在 C++ 中 throw; 在 catch 块内执行时,会在块外重新抛出当前捕获的异常.

                In C++ throw; when executed inside a catch block rethrows the currently caught exception outside the block.

                在这个答案中,一个例外的想法当经常使用复杂的异常处理时,调度程序是作为减少代码重复的解决方案提出的:

                In this answer an idea of exception dispatcher is brought up as a solution to reducing code duplication when using complex exception handling often:

                try {
                    CodeThatMightThrow();
                } catch(...) {
                    ExceptionHandler();
                }
                
                void ExceptionHandler()
                {
                    try {
                        throw;
                    } catch( FileException* e ) {
                        //do handling with some complex logic
                        delete e;
                    } catch( GenericException* e ) {
                        //do handling with other complex logic
                        delete e;
                    }
                }
                

                抛出一个指针或一个值没有任何区别,所以这是不可能的.

                Throwing a pointer or a value doesn't make any difference so it's out of the question.

                如果不是从 catch 块调用 ExceptionHandler() 会发生什么?

                What happens if ExceptionHandler() is called not from a catch block?

                我用 VC7 试过这段代码:

                I tried this code with VC7:

                int main( int, char** )
                {   
                    try {
                        throw;
                    } catch( ... ) {
                        MessageBox( 0, "", "", 0 );
                    }
                    return 0;
                 }
                

                首先它使调试器指示第一次机会异常,然后立即指示未处理的异常.如果我在调试器之外运行此代码,程序会以与调用 abort() 相同的方式崩溃.

                First it causes the debugger to indicate a first-chance exception, then immediately an unhandled exception. If I run this code outside the debugger the program crashes the same way as if abort() has been called.

                这种情况下的预期行为是什么?

                What is the expected behaviour for such situations?

                推荐答案

                From the Standard, 15.1/8

                From the Standard, 15.1/8

                如果当前没有处理异常,执行一个没有操作数的throw-expression调用std::terminate().

                If no exception is presently being handled, executing a throw-expression with no operand calls std::terminate().

                这篇关于如果投掷会发生什么;语句是在 catch 块之外执行的吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:“第一次机会例外"在 MFC 应用程序中的含义 下一篇:为什么 rand() 编译时不包含 cstdlib 或使用命名空间

                相关文章

                最新文章

                  <small id='5Vlq9'></small><noframes id='5Vlq9'>

                  <legend id='5Vlq9'><style id='5Vlq9'><dir id='5Vlq9'><q id='5Vlq9'></q></dir></style></legend>

                  1. <i id='5Vlq9'><tr id='5Vlq9'><dt id='5Vlq9'><q id='5Vlq9'><span id='5Vlq9'><b id='5Vlq9'><form id='5Vlq9'><ins id='5Vlq9'></ins><ul id='5Vlq9'></ul><sub id='5Vlq9'></sub></form><legend id='5Vlq9'></legend><bdo id='5Vlq9'><pre id='5Vlq9'><center id='5Vlq9'></center></pre></bdo></b><th id='5Vlq9'></th></span></q></dt></tr></i><div id='5Vlq9'><tfoot id='5Vlq9'></tfoot><dl id='5Vlq9'><fieldset id='5Vlq9'></fieldset></dl></div>

                      <bdo id='5Vlq9'></bdo><ul id='5Vlq9'></ul>

                    <tfoot id='5Vlq9'></tfoot>