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

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

      <legend id='mnAWE'><style id='mnAWE'><dir id='mnAWE'><q id='mnAWE'></q></dir></style></legend>
        <bdo id='mnAWE'></bdo><ul id='mnAWE'></ul>
    2. <tfoot id='mnAWE'></tfoot>

      C++ 捕获所有异常

      时间:2023-08-03
          <tbody id='pn9j1'></tbody>
        <tfoot id='pn9j1'></tfoot>

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

          <bdo id='pn9j1'></bdo><ul id='pn9j1'></ul>
        • <legend id='pn9j1'><style id='pn9j1'><dir id='pn9j1'><q id='pn9j1'></q></dir></style></legend>

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

                本文介绍了C++ 捕获所有异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                是否有 Java 的 C++ 等价物

                Is there a c++ equivalent of Java's

                try {
                    ...
                }
                catch (Throwable t) {
                    ...
                }
                

                我正在尝试调试调用本机 Windows 函数的 Java/jni 代码,但虚拟机不断崩溃.本机代码在单元测试中看起来很好,只有在通过 jni 调用时才会崩溃.通用的异常捕获机制将证明非常有用.

                I am trying to debug Java/jni code that calls native windows functions and the virtual machine keeps crashing. The native code appears fine in unit testing and only seems to crash when called through jni. A generic exception catching mechanism would prove extremely useful.

                推荐答案

                try{
                    // ...
                } catch (...) {
                    // ...
                }
                

                将捕获所有 C++ 异常,但它应该被认为是糟糕的设计.您可以使用 c++11 的新 current_exception 机制,但是如果您没有能力使用 c++11(需要重写的遗留代码系统),那么您就没有用于获取消息或名称的命名异常指针.您可能希望为您可以捕获的各种异常添加单独的 catch 子句,并且只捕获底部的所有内容以记录意外异常.例如:

                will catch all C++ exceptions, but it should be considered bad design. You can use c++11's new current_exception mechanism, but if you don't have the ability to use c++11 (legacy code systems requiring a rewrite), then you have no named exception pointer to use to get a message or name. You may want to add separate catch clauses for the various exceptions you can catch, and only catch everything at the bottom to record an unexpected exception. E.g.:

                try{
                    // ...
                } catch (const std::exception& ex) {
                    // ...
                } catch (const std::string& ex) {
                    // ...
                } catch (...) {
                    // ...
                }
                

                这篇关于C++ 捕获所有异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:为什么 C++ 不使用 std::nested_exception 来允许从析构 下一篇:如何捕捉空指针异常?

                相关文章

                最新文章

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

                <legend id='CBK0V'><style id='CBK0V'><dir id='CBK0V'><q id='CBK0V'></q></dir></style></legend>

                  <tfoot id='CBK0V'></tfoot>

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

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