问题描述
我有一个C ++应用程序调用的(SQLite是在C)的这反过来又可以调用C实现我的回调函数++。 SQLite是编译成静态库。
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.
如果一个异常逃脱我的回调将它通过的SQLite的C code到C ++的code安全传播调用sqlite3_exec()?
If an exception escapes my callback will it propagate safely through the C code of SQLite to the C++ code calling sqlite3_exec()?
推荐答案
我的猜测是,这是编译器相关的。然而,在回调抛出一个异常将是一个非常糟糕的主意。要么它会平出不工作,或者在SQLite库的C code将无法处理。试想,如果这是SQLite的一些code:
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 );
}
如果异常工程,在C code的追赶它没有可能的方式,和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 code传播?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!