mirror of
https://github.com/catchorg/Catch2.git
synced 2025-06-02 18:07:59 +00:00
exception translators considered even for types deriving from std::exception, now
- also added docs for exception translators - updated approvals
This commit is contained in:
parent
ed6e9128a4
commit
a49f088032
8 changed files with 101 additions and 28 deletions
|
@ -106,22 +106,50 @@ private:
|
|||
std::string m_msg;
|
||||
};
|
||||
|
||||
class CustomStdException : public std::exception
|
||||
{
|
||||
public:
|
||||
CustomStdException( const std::string& msg )
|
||||
: m_msg( msg )
|
||||
{}
|
||||
|
||||
std::string getMessage() const
|
||||
{
|
||||
return m_msg;
|
||||
}
|
||||
|
||||
private:
|
||||
std::string m_msg;
|
||||
};
|
||||
|
||||
|
||||
CATCH_TRANSLATE_EXCEPTION( CustomException& ex )
|
||||
{
|
||||
return ex.getMessage();
|
||||
}
|
||||
|
||||
CATCH_TRANSLATE_EXCEPTION( CustomStdException& ex )
|
||||
{
|
||||
return ex.getMessage();
|
||||
}
|
||||
|
||||
CATCH_TRANSLATE_EXCEPTION( double& ex )
|
||||
{
|
||||
return Catch::toString( ex );
|
||||
}
|
||||
|
||||
TEST_CASE("Unexpected custom exceptions can be translated", "[.][failing]" )
|
||||
TEST_CASE("Non-std exceptions can be translated", "[.][failing]" )
|
||||
{
|
||||
if( Catch::alwaysTrue() )
|
||||
throw CustomException( "custom exception" );
|
||||
}
|
||||
|
||||
TEST_CASE("Custom std-exceptions can be custom translated", "[.][failing]" )
|
||||
{
|
||||
if( Catch::alwaysTrue() )
|
||||
throw CustomException( "custom std exception" );
|
||||
}
|
||||
|
||||
inline void throwCustom() {
|
||||
if( Catch::alwaysTrue() )
|
||||
throw CustomException( "custom exception - not std" );
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue