Read-only mirrors. Development, issues and pull requests are on GitHub.

summaryrefslogtreecommitdiffhomepage
path: root/include
diff options
context:
space:
mode:
authorPhil Nash2012-02-17 19:50:59 +0000
committerPhil Nash2012-02-17 19:50:59 +0000
commit333e6e625484a968b97dd5dd7e2eeea800c732f8 (patch)
tree72e72db7384a5d2ca44cbdf15834fd586ab838b8 /include
parenta57b025c9c07df56a749d340a19db4d70a5ac9bb (diff)
downloadcatch3-333e6e625484a968b97dd5dd7e2eeea800c732f8.tar.gz
Improved exception reporting
Refactored exception handling (handle more in the translator) and report exceptions in CHECKs
Diffstat (limited to 'include')
-rw-r--r--include/internal/catch_capture.hpp20
-rw-r--r--include/internal/catch_exception_translator_registry.hpp21
-rw-r--r--include/internal/catch_runner_impl.hpp17
3 files changed, 35 insertions, 23 deletions
diff --git a/include/internal/catch_capture.hpp b/include/internal/catch_capture.hpp
index 2449f60b..d19f4c24 100644
--- a/include/internal/catch_capture.hpp
+++ b/include/internal/catch_capture.hpp
@@ -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 ); \
diff --git a/include/internal/catch_exception_translator_registry.hpp b/include/internal/catch_exception_translator_registry.hpp
index 3c677545..45ed0971 100644
--- a/include/internal/catch_exception_translator_registry.hpp
+++ b/include/internal/catch_exception_translator_registry.hpp
@@ -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() );
+ }
}
///////////////////////////////////////////////////////////////////////
diff --git a/include/internal/catch_runner_impl.hpp b/include/internal/catch_runner_impl.hpp
index d72a844f..9247cb62 100644
--- a/include/internal/catch_runner_impl.hpp
+++ b/include/internal/catch_runner_impl.hpp
@@ -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() );