This has been driving me crazy all night.
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;
};
I throw this custom exception from a library as follows
throw Exception( "Error message" );
and catch it in main via
try
{
regex pattern(R"(a*)");
Id::set_pattern_validator(pattern);
assert(false);
}
catch( Exception const& exception )
{
assert(true);
}
Id::set_pattern_validator
is a static method within the Id class of the library and the source of the exception. I've tried everything i can to catch the exception but it fails to be caught.
catch( Exception )
catch( std::exception )
catch( ... )
Nada!
Terminal output is as follows.
"Terminate called after throwing an instance of 'Exception' what(): The pattern validator cannot be altered once set. Abort trap."
Now short of sacrificing a goat I'm at a loss on what to try next... any hints/tips???
Note: If i throw the custom exception within main i can catch it no problem.
Mac OS X environment using GCC with the C++0x support.
EDIT: A solution for now is to continue development on a linux based system (Fedora). I will not be accepting an answer as of yet. Thanks for everyones help.
std::bad_alloc
). Also take a look at Boost.Exception. – Kvstd::bad_alloc
is definitely better. Edit: Boost.Exception uses pimpl. – Realgar