mirror of
https://github.com/catchorg/Catch2.git
synced 2025-05-31 00:47:56 +00:00
First cut of custom exception support
This commit is contained in:
parent
d4117b9208
commit
9430a2c4c8
8 changed files with 192 additions and 2 deletions
67
internal/catch_interfaces_exception.h
Normal file
67
internal/catch_interfaces_exception.h
Normal file
|
@ -0,0 +1,67 @@
|
|||
/*
|
||||
* catch_exception_interfaces.h
|
||||
* Catch
|
||||
*
|
||||
* 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_INTERFACES_EXCEPTIONS_H_INCLUDED
|
||||
#define TWOBLUECUBES_CATCH_INTERFACES_EXCEPTIONS_H_INCLUDED
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace Catch
|
||||
{
|
||||
typedef std::string(*exceptionTranslateFunction)();
|
||||
|
||||
struct IExceptionTranslator
|
||||
{
|
||||
virtual ~IExceptionTranslator(){}
|
||||
virtual std::string translate() const = 0;
|
||||
};
|
||||
|
||||
struct IExceptionTranslatorRegistry
|
||||
{
|
||||
virtual ~IExceptionTranslatorRegistry
|
||||
()
|
||||
{}
|
||||
|
||||
virtual void registerTranslator
|
||||
( IExceptionTranslator* translator
|
||||
) = 0;
|
||||
virtual std::string translateActiveException
|
||||
() const = 0;
|
||||
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
class ExceptionTranslator : public IExceptionTranslator
|
||||
{
|
||||
public:
|
||||
ExceptionTranslator()
|
||||
{
|
||||
Catch::Hub::getExceptionTranslatorRegistry().registerTranslator( this );
|
||||
}
|
||||
|
||||
virtual std::string translate() const
|
||||
{
|
||||
try
|
||||
{
|
||||
throw;
|
||||
}
|
||||
catch( T& ex )
|
||||
{
|
||||
return translate( ex );
|
||||
}
|
||||
}
|
||||
|
||||
protected:
|
||||
std::string translate( T& ex ) const;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // TWOBLUECUBES_CATCH_INTERFACES_EXCEPTIONS_H_INCLUDED
|
Loading…
Add table
Add a link
Reference in a new issue