如果异常被抛出&QUOT会发生什么;通过" C code吗? [英] What happens if exception gets thrown "through" c code?

查看:151
本文介绍了如果异常被抛出&QUOT会发生什么;通过" C code吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:结果
  <一href=\"http://stackoverflow.com/questions/2101390/will-c-exceptions-safely-propagate-through-c-$c$c\">Will C ++异常安全地到C code传播?

如果您有C code,例如PNG lib中,与用C ++和异常得到投掷由于一些IO错误你自己的IO处理程序。是否确定要让它去通过C code和抓住它的C code之外吗?我知道,照顾有内存泄漏采取但通常都得到结构pre分配。

If you have c code, for example the png lib, with your own io handlers which are written in c++ and an exception gets thrown due to some io error. is it ok to let it go through the c code and catch it outside of the c code? i know that care has to be taken with memory leaks but typically all structures get pre-allocated.

推荐答案

这完全取决于这是否会工作或没有编译器。语文水平无明显能说一下其他的语言应该做些什么事情。

It is entirely up to the compiler if this will work or not. None of the language standards can obviously say anything about what the other language should do.

在最好的情况下,该异常将通过C code和返回到下一个C ++同时可能泄露任何动态分配的C结构水平。在不太好的情况下,它会和好如初!

In the best case, the exception will pass the C code and get back to the next C++ level while possibly leaking any dynamically allocated C structures. In the less good case, it will crash and burn!

一possibilty当然编译C code作为C ++,同时还检查它是例外中性的。

One possibilty is of course to compile the C code as C++, while also checking that it is exception neutral.

这篇关于如果异常被抛出&QUOT会发生什么;通过&QUOT; C code吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆