我正在使用 mysql c++ 连接器和这个(有点简化的)代码。
try
{
statement->setString(1, word);
statement->executeUpdate();
}
catch( sql::SQLException& e )
{
// I don't get here
return sqlerrno_to_error_code( e.getErrorCode() );
}
catch( std::exception& e )
{
// I do get here and the cast works
sql::SQLException& sqle = (sql::SQLException&) e;
return sqlerrno_to_error_code( sqle.getErrorCode() );
}
连接器应该抛出 sql::SQLException ,它派生自 std::exception 并具有一些附加方法,例如getErrorCode()
.
抛出的异常在第二个中被捕获catch
块,但可以转换为(并用作)sql::SQLException
成功地。
更奇怪的是,不同可执行文件中的类似代码会捕获sql::SQLException
正如预期的那样。它们之间的区别在于第一个位于共享对象(.so)中,该对象加载了dlopen()
.
RHEL 5.7 32 位,gcc 4.1.2
请参阅注释dynamic_cast, throw, typeid不使用共享库在海湾合作委员会常见问题页面上。
因为你正在使用dlopen()
,您需要将可执行文件链接到-E
标志(或通过
-Wl,-E
to g++
if g++
正在调用链接器)并传递RTLD_GLOBAL
标记为dlopen()
.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)