mirror of
https://github.com/catchorg/Catch2.git
synced 2024-12-22 19:33:29 +01:00
Cleanup in translating exceptions to messages
This commit is contained in:
parent
b3ebce715e
commit
3230760db2
@ -13,6 +13,20 @@
|
||||
|
||||
namespace Catch {
|
||||
|
||||
namespace {
|
||||
static std::string tryTranslators(
|
||||
std::vector<
|
||||
Detail::unique_ptr<IExceptionTranslator const>> const& translators ) {
|
||||
if ( translators.empty() ) {
|
||||
std::rethrow_exception( std::current_exception() );
|
||||
} else {
|
||||
return translators[0]->translate( translators.begin() + 1,
|
||||
translators.end() );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
ExceptionTranslatorRegistry::~ExceptionTranslatorRegistry() {
|
||||
}
|
||||
|
||||
@ -37,7 +51,7 @@ namespace Catch {
|
||||
// First we try user-registered translators. If none of them can
|
||||
// handle the exception, it will be rethrown handled by our defaults.
|
||||
try {
|
||||
return tryTranslators();
|
||||
return tryTranslators(m_translators);
|
||||
}
|
||||
// To avoid having to handle TFE explicitly everywhere, we just
|
||||
// rethrow it so that it goes back up the caller.
|
||||
@ -61,23 +75,10 @@ namespace Catch {
|
||||
}
|
||||
}
|
||||
|
||||
std::string ExceptionTranslatorRegistry::tryTranslators() const {
|
||||
if (m_translators.empty()) {
|
||||
std::rethrow_exception(std::current_exception());
|
||||
} else {
|
||||
return m_translators[0]->translate(m_translators.begin() + 1, m_translators.end());
|
||||
}
|
||||
}
|
||||
|
||||
#else // ^^ Exceptions are enabled // Exceptions are disabled vv
|
||||
std::string ExceptionTranslatorRegistry::translateActiveException() const {
|
||||
CATCH_INTERNAL_ERROR("Attempted to translate active exception under CATCH_CONFIG_DISABLE_EXCEPTIONS!");
|
||||
}
|
||||
|
||||
std::string ExceptionTranslatorRegistry::tryTranslators() const {
|
||||
CATCH_INTERNAL_ERROR("Attempted to use exception translators under CATCH_CONFIG_DISABLE_EXCEPTIONS!");
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
}
|
||||
|
@ -21,7 +21,6 @@ namespace Catch {
|
||||
~ExceptionTranslatorRegistry() override;
|
||||
void registerTranslator( Detail::unique_ptr<IExceptionTranslator>&& translator );
|
||||
std::string translateActiveException() const override;
|
||||
std::string tryTranslators() const;
|
||||
|
||||
private:
|
||||
ExceptionTranslators m_translators;
|
||||
|
Loading…
Reference in New Issue
Block a user