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

    1. <tfoot id='OeRIa'></tfoot>
      <legend id='OeRIa'><style id='OeRIa'><dir id='OeRIa'><q id='OeRIa'></q></dir></style></legend>

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

        跨 DLL 边界抛出 C++ 异常

        Throwing C++ exceptions across DLL boundaries(跨 DLL 边界抛出 C++ 异常)

      1. <small id='nTkMq'></small><noframes id='nTkMq'>

      2. <tfoot id='nTkMq'></tfoot>
            <tbody id='nTkMq'></tbody>

              • <bdo id='nTkMq'></bdo><ul id='nTkMq'></ul>
                  <legend id='nTkMq'><style id='nTkMq'><dir id='nTkMq'><q id='nTkMq'></q></dir></style></legend>
                1. <i id='nTkMq'><tr id='nTkMq'><dt id='nTkMq'><q id='nTkMq'><span id='nTkMq'><b id='nTkMq'><form id='nTkMq'><ins id='nTkMq'></ins><ul id='nTkMq'></ul><sub id='nTkMq'></sub></form><legend id='nTkMq'></legend><bdo id='nTkMq'><pre id='nTkMq'><center id='nTkMq'></center></pre></bdo></b><th id='nTkMq'></th></span></q></dt></tr></i><div id='nTkMq'><tfoot id='nTkMq'></tfoot><dl id='nTkMq'><fieldset id='nTkMq'></fieldset></dl></div>
                  本文介绍了跨 DLL 边界抛出 C++ 异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我已经阅读了关于不应如何在一个 DLL 中分配堆内存并从该 DLL 外部释放它的各种内容.但是如果抛出一个只是临时的异常对象(大多数异常对象都是如此)呢?例如:

                  I've read various things about how one should not allocate heap memory in one DLL and deallocate it from outside that DLL. But what about throwing an exception object that is a just a temporary (as most exception objects are)? E.g.:

                  throw my_exception( args ); // temporary: no heap allocation
                  

                  当异常对象在 DLL 外被捕获时,最终会执行该对象的析构函数,并回收该对象的非堆内存.因为它不是堆内存所以可以吗?

                  When the exception object is caught outside the DLL, the destructor for that object will eventually be executed and the non-heap memory for the object will be reclaimed. Is that OK since it's not heap memory?

                  推荐答案

                  只有当所有模块都使用相同的 C++ 运行时(在这种情况下它们也共享一个堆)时,才可能跨 DLL 边界抛出 C++ 异常.但这可能是一种维护负担,尤其是当涉及多个供应商的库时,因此不鼓励这样做.

                  Throwing C++ exceptions across DLL boundaries is only possible when all modules use the same C++ runtime, in which case they share a heap as well. But this can be a maintenance burden, especially when libraries from multiple vendors are involved, so it is discouraged.

                  如果您想要跨多个编译器/编译器版本/编译器设置进行可移植的错误处理,请使用返回代码或操作系统提供的异常(例如 Windows 上的 SEH)/

                  If you want error-handling which is portable across multiple compilers/compiler versions/compiler settings, either use return codes or OS-provided exceptions (e.g. SEH on Windows)/

                  这篇关于跨 DLL 边界抛出 C++ 异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  What is inside .lib file of Static library, Statically linked dynamic library and dynamically linked dynamic library?(静态库、静态链接动态库和动态链接动态库的 .lib 文件里面是什么?)
                  How do I load a C DLL from the SXS in Python?(如何从 Python 中的 SXS 加载 C DLL?)
                  Can Cython code be compiled to a dll so C++ application can call it?(Cython 代码可以编译成 dll 以便 C++ 应用程序可以调用它吗?)
                  Delay Loading DLLs(延迟加载 DLL)
                  Loading a dll from a dll?(从 dll 加载 dll?)
                  C++11 std::mutex in Visual Studio 2012 deadlock when locked from DllMain()(当从 DllMain() 锁定时,Visual Studio 2012 中的 C++11 std::mutex 会死锁)

                2. <tfoot id='MKypf'></tfoot>
                  <legend id='MKypf'><style id='MKypf'><dir id='MKypf'><q id='MKypf'></q></dir></style></legend>

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

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

                              <tbody id='MKypf'></tbody>

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