mirror of
https://github.com/catchorg/Catch2.git
synced 2025-08-01 12:55:40 +02:00
Improved exception reporting
Refactored exception handling (handle more in the translator) and report exceptions in CHECKs
This commit is contained in:
@@ -684,8 +684,20 @@ inline bool isTrue
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
#define INTERNAL_CATCH_TEST( expr, isNot, stopOnFailure, macroName ) \
|
||||
INTERNAL_CATCH_ACCEPT_EXPR( ( Catch::ResultBuilder( __FILE__, __LINE__, macroName, #expr, isNot )->*expr ), stopOnFailure ); \
|
||||
if( Catch::isTrue( false ) ){ bool internal_catch_dummyResult = ( expr ); Catch::isTrue( internal_catch_dummyResult ); }
|
||||
try \
|
||||
{ \
|
||||
INTERNAL_CATCH_ACCEPT_EXPR( ( Catch::ResultBuilder( __FILE__, __LINE__, macroName, #expr, isNot )->*expr ), stopOnFailure ); \
|
||||
if( Catch::isTrue( false ) ){ bool internal_catch_dummyResult = ( expr ); Catch::isTrue( internal_catch_dummyResult ); } \
|
||||
} \
|
||||
catch( Catch::TestFailureException& ) \
|
||||
{ \
|
||||
throw; \
|
||||
} \
|
||||
catch( ... ) \
|
||||
{ \
|
||||
INTERNAL_CATCH_ACCEPT_EXPR( ( Catch::ResultBuilder( __FILE__, __LINE__, macroName, #expr ) << Catch::Hub::getExceptionTranslatorRegistry().translateActiveException() ).setResultType( Catch::ResultWas::ThrewException ), false ); \
|
||||
throw; \
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
#define INTERNAL_CATCH_IF( expr, isNot, stopOnFailure, macroName ) \
|
||||
@@ -704,10 +716,6 @@ inline bool isTrue
|
||||
expr; \
|
||||
INTERNAL_CATCH_ACCEPT_EXPR( Catch::ResultBuilder( __FILE__, __LINE__, macroName, #expr ).setResultType( Catch::ResultWas::Ok ), stopOnFailure ); \
|
||||
} \
|
||||
catch( std::exception& internal_catch_exception ) \
|
||||
{ \
|
||||
INTERNAL_CATCH_ACCEPT_EXPR( ( Catch::ResultBuilder( __FILE__, __LINE__, macroName, #expr ) << internal_catch_exception.what() ).setResultType( Catch::ResultWas::ThrewException ), stopOnFailure ); \
|
||||
} \
|
||||
catch( ... ) \
|
||||
{ \
|
||||
INTERNAL_CATCH_ACCEPT_EXPR( ( Catch::ResultBuilder( __FILE__, __LINE__, macroName, #expr ) << Catch::Hub::getExceptionTranslatorRegistry().translateActiveException() ).setResultType( Catch::ResultWas::ThrewException ), stopOnFailure ); \
|
||||
|
@@ -32,7 +32,26 @@ namespace Catch
|
||||
()
|
||||
const
|
||||
{
|
||||
return tryTranslators( m_translators.begin() );
|
||||
try
|
||||
{
|
||||
throw;
|
||||
}
|
||||
catch( std::exception& ex )
|
||||
{
|
||||
return ex.what();
|
||||
}
|
||||
catch( std::string& msg )
|
||||
{
|
||||
return msg;
|
||||
}
|
||||
catch( const char* msg )
|
||||
{
|
||||
return msg;
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
return tryTranslators( m_translators.begin() );
|
||||
}
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
|
@@ -391,7 +391,7 @@ namespace Catch
|
||||
|
||||
m_reporter->EndTestCase( testInfo, m_successes - prevSuccessCount, m_failures - prevFailureCount, redirectedCout, redirectedCerr );
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
virtual std::size_t getSuccessCount
|
||||
()
|
||||
@@ -601,21 +601,6 @@ namespace Catch
|
||||
{
|
||||
// This just means the test was aborted due to failure
|
||||
}
|
||||
catch( std::exception& ex )
|
||||
{
|
||||
acceptMessage( ex.what() );
|
||||
acceptResult( ResultWas::ThrewException );
|
||||
}
|
||||
catch( std::string& msg )
|
||||
{
|
||||
acceptMessage( msg );
|
||||
acceptResult( ResultWas::ThrewException );
|
||||
}
|
||||
catch( const char* msg )
|
||||
{
|
||||
acceptMessage( msg );
|
||||
acceptResult( ResultWas::ThrewException );
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
acceptMessage( Catch::Hub::getExceptionTranslatorRegistry().translateActiveException() );
|
||||
|
Reference in New Issue
Block a user