| 
									
										
										
										
											2011-04-20 15:40:40 +01:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  *  Created by Phil on 20/04/2011. | 
					
						
							|  |  |  |  *  Copyright 2011 Two Blue Cubes Ltd. All rights reserved. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  *  Distributed under the Boost Software License, Version 1.0. (See accompanying | 
					
						
							|  |  |  |  *  file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
 | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | #ifndef TWOBLUECUBES_CATCH_EXCEPTION_TRANSLATOR_HPP_INCLUDED
 | 
					
						
							|  |  |  | #define TWOBLUECUBES_CATCH_EXCEPTION_TRANSLATOR_HPP_INCLUDED
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "catch_interfaces_exception.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-05-16 08:02:20 +01:00
										 |  |  | namespace Catch { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     class ExceptionTranslatorRegistry : public IExceptionTranslatorRegistry { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         ~ExceptionTranslatorRegistry() { | 
					
						
							| 
									
										
										
										
											2012-02-18 19:14:09 +00:00
										 |  |  |             deleteAll( m_translators ); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2012-05-16 08:02:20 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |         virtual void registerTranslator( IExceptionTranslator* translator ) { | 
					
						
							| 
									
										
										
										
											2011-04-20 15:40:40 +01:00
										 |  |  |             m_translators.push_back( translator ); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |          | 
					
						
							| 
									
										
										
										
											2012-05-16 08:02:20 +01:00
										 |  |  |         virtual std::string translateActiveException() const { | 
					
						
							|  |  |  |             try { | 
					
						
							| 
									
										
										
										
											2012-02-17 19:50:59 +00:00
										 |  |  |                 throw; | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2012-05-16 08:02:20 +01:00
										 |  |  |             catch( std::exception& ex ) { | 
					
						
							| 
									
										
										
										
											2012-02-17 19:50:59 +00:00
										 |  |  |                 return ex.what(); | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2012-05-16 08:02:20 +01:00
										 |  |  |             catch( std::string& msg ) { | 
					
						
							| 
									
										
										
										
											2012-02-17 19:50:59 +00:00
										 |  |  |                 return msg; | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2012-05-16 08:02:20 +01:00
										 |  |  |             catch( const char* msg ) { | 
					
						
							| 
									
										
										
										
											2012-02-17 19:50:59 +00:00
										 |  |  |                 return msg; | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2012-05-16 08:02:20 +01:00
										 |  |  |             catch(...) { | 
					
						
							| 
									
										
										
										
											2012-02-17 19:50:59 +00:00
										 |  |  |                 return tryTranslators( m_translators.begin() ); | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2011-04-20 15:40:40 +01:00
										 |  |  |         } | 
					
						
							|  |  |  |          | 
					
						
							| 
									
										
										
										
											2012-05-16 08:02:20 +01:00
										 |  |  |         std::string tryTranslators( std::vector<IExceptionTranslator*>::const_iterator it ) const { | 
					
						
							| 
									
										
										
										
											2011-04-20 15:40:40 +01:00
										 |  |  |             if( it == m_translators.end() ) | 
					
						
							|  |  |  |                 return "Unknown exception"; | 
					
						
							|  |  |  |              | 
					
						
							| 
									
										
										
										
											2012-05-16 08:02:20 +01:00
										 |  |  |             try { | 
					
						
							| 
									
										
										
										
											2011-04-20 15:40:40 +01:00
										 |  |  |                 return (*it)->translate(); | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2012-05-16 08:02:20 +01:00
										 |  |  |             catch(...) { | 
					
						
							| 
									
										
										
										
											2011-04-20 15:40:40 +01:00
										 |  |  |                 return tryTranslators( it+1 ); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |          | 
					
						
							|  |  |  |     private: | 
					
						
							|  |  |  |         std::vector<IExceptionTranslator*> m_translators; | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #endif // TWOBLUECUBES_CATCH_EXCEPTION_TRANSLATOR_HPP_INCLUDED
 |