C ++异常会通过C代码安全地传播吗? [英] Will C++ exceptions safely propagate through C code?
问题描述
如果异常转义我的回调,它将通过SQLite的C代码安全传播到调用sqlite3_exec()的C ++代码? p>
我的猜测是这是编译器依赖的。但是,在回调中抛出异常将是一个非常糟糕的主意。否则它将不能正常工作,否则SQLite库中的C代码将无法处理它。考虑这是否是SQLite中的一些代码:
{
char * p = malloc(1000);
...
call_the_callback(); //可能会抛出一个异常
...
free(p);
}
如果异常工作,C代码没有可能的方法它和p永远不会被释放。当然,图书馆可能分配的任何其他资源也一样。
I have a C++ application that calls SQLite's (SQLite is in C) sqlite3_exec() which in turn can call my callback function implemented in C++. SQLite is compiled into a static library.
If an exception escapes my callback will it propagate safely through the C code of SQLite to the C++ code calling sqlite3_exec()?
My guess is that this is compiler dependent. However, throwing an exception in the callback would be a very bad idea. Either it will flat-out not work, or the C code in the SQLite library will be unable to handle it. Consider if this is some code in SQLite:
{
char * p = malloc( 1000 );
...
call_the_callback(); // might throw an exception
...
free( p );
}
If the exception "works", the C code has no possible way of catching it, and p will never be freed. The same goes for any other resources the library may have allocated, of course.
这篇关于C ++异常会通过C代码安全地传播吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!