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

summaryrefslogtreecommitdiffhomepage
path: root/include
diff options
context:
space:
mode:
authorPhil Nash2015-11-18 08:39:21 +0000
committerPhil Nash2015-11-18 08:39:21 +0000
commita49f088032be4d9d2e1c87f888254974c79fc5b8 (patch)
tree3253b3da15badc7694c694567c546476a7bbebf4 /include
parented6e9128a4f1d8c5e24be01d8ad9341f83a39562 (diff)
downloadcatch3-a49f088032be4d9d2e1c87f888254974c79fc5b8.tar.gz
exception translators considered even for types deriving from std::exception, now
- also added docs for exception translators - updated approvals
Diffstat (limited to 'include')
-rw-r--r--include/internal/catch_exception_translator_registry.hpp21
-rw-r--r--include/internal/catch_interfaces_exception.h14
2 files changed, 19 insertions, 16 deletions
diff --git a/include/internal/catch_exception_translator_registry.hpp b/include/internal/catch_exception_translator_registry.hpp
index 29ddf8e7..c4bdb400 100644
--- a/include/internal/catch_exception_translator_registry.hpp
+++ b/include/internal/catch_exception_translator_registry.hpp
@@ -32,13 +32,13 @@ namespace Catch {
#ifdef __OBJC__
// In Objective-C try objective-c exceptions first
@try {
- throw;
+ return tryTranslators();
}
@catch (NSException *exception) {
return Catch::toString( [exception description] );
}
#else
- throw;
+ return tryTranslators();
#endif
}
catch( TestFailureException& ) {
@@ -54,20 +54,15 @@ namespace Catch {
return msg;
}
catch(...) {
- return tryTranslators( m_translators.begin() );
+ return "Unknown exception";
}
}
- std::string tryTranslators( std::vector<const IExceptionTranslator*>::const_iterator it ) const {
- if( it == m_translators.end() )
- return "Unknown exception";
-
- try {
- return (*it)->translate();
- }
- catch(...) {
- return tryTranslators( it+1 );
- }
+ std::string tryTranslators() const {
+ if( m_translators.empty() )
+ throw;
+ else
+ return m_translators[0]->translate( m_translators.begin()+1, m_translators.end() );
}
private:
diff --git a/include/internal/catch_interfaces_exception.h b/include/internal/catch_interfaces_exception.h
index c2fc5bf5..67247e1e 100644
--- a/include/internal/catch_interfaces_exception.h
+++ b/include/internal/catch_interfaces_exception.h
@@ -9,15 +9,20 @@
#define TWOBLUECUBES_CATCH_INTERFACES_EXCEPTION_H_INCLUDED
#include <string>
+#include <vector>
+
#include "catch_interfaces_registry_hub.h"
namespace Catch {
typedef std::string(*exceptionTranslateFunction)();
+ struct IExceptionTranslator;
+ typedef std::vector<const IExceptionTranslator*> ExceptionTranslators;
+
struct IExceptionTranslator {
virtual ~IExceptionTranslator();
- virtual std::string translate() const = 0;
+ virtual std::string translate( ExceptionTranslators::const_iterator it, ExceptionTranslators::const_iterator itEnd ) const = 0;
};
struct IExceptionTranslatorRegistry {
@@ -35,9 +40,12 @@ namespace Catch {
: m_translateFunction( translateFunction )
{}
- virtual std::string translate() const {
+ virtual std::string translate( ExceptionTranslators::const_iterator it, ExceptionTranslators::const_iterator itEnd ) const CATCH_OVERRIDE {
try {
- throw;
+ if( it == itEnd )
+ throw;
+ else
+ return (*it)->translate( it+1, itEnd );
}
catch( T& ex ) {
return m_translateFunction( ex );