这让我整晚都发疯了。
class ExceptionImpl;
/**
* Custom Exception.
*/
class Exception : public virtual std::exception
{
public:
Exception( const Exception& original );
Exception( const std::string& message );
virtual ~Exception( void ) throw( );
virtual const char* what( void ) const throw( );
private:
const std::unique_ptr< ExceptionImpl > m_pimpl;
};
我从库中抛出这个自定义异常,如下所示
throw Exception( "Error message" );
并通过主要途径抓住它
try
{
regex pattern(R"(a*)");
Id::set_pattern_validator(pattern);
assert(false);
}
catch( Exception const& exception )
{
assert(true);
}
Id::set_pattern_validator
是库的 Id 类中的一个静态方法,也是异常的来源。我已经尽我所能来捕捉异常,但它没有被捕捉到。
catch( Exception )
catch( std::exception )
catch( ... )
Nada!
终端输出如下。
“在抛出 'Exception' what() 的实例后调用终止:模式验证器一旦设置就无法更改。中止陷阱。”
现在没有牺牲一只山羊,我不知道接下来要尝试什么……任何提示/提示???
注意:如果我在 main 中抛出自定义异常,我可以毫无问题地捕获它。
使用 GCC 并支持 C++0x 的 Mac OS X 环境。
编辑:目前的解决方案是继续在基于 linux 的系统(Fedora)上进行开发。到目前为止,我不会接受答案。感谢大家的帮助。