mirror of
				https://github.com/catchorg/Catch2.git
				synced 2025-10-31 12:17:11 +01: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:
		| @@ -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: | ||||
|   | ||||
| @@ -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 ); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Phil Nash
					Phil Nash