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

summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorMartin Hořeňovský2020-05-19 21:23:35 +0200
committerMartin Hořeňovský2020-05-20 08:15:27 +0200
commit4394d3ae65e076c749dc95a27f3178b94ba09e94 (patch)
tree910c1ab3aa13847da7a5dacef60a258483337e8d
parent4b2f1da02a37d111b572551f4bd8ed765b06ca28 (diff)
downloadcatch3-4394d3ae65e076c749dc95a27f3178b94ba09e94.tar.gz
Translate exceptions by const reference instead of plain ref
-rw-r--r--docs/tostring.md2
-rw-r--r--src/catch2/catch_translate_exception.hpp8
-rw-r--r--tests/SelfTest/UsageTests/Exception.tests.cpp6
3 files changed, 8 insertions, 8 deletions
diff --git a/docs/tostring.md b/docs/tostring.md
index 156c895a..87a0caf0 100644
--- a/docs/tostring.md
+++ b/docs/tostring.md
@@ -64,7 +64,7 @@ namespace Catch {
By default all exceptions deriving from `std::exception` will be translated to strings by calling the `what()` method. For exception types that do not derive from `std::exception` - or if `what()` does not return a suitable string - use `CATCH_TRANSLATE_EXCEPTION`. This defines a function that takes your exception type, by reference, and returns a string. It can appear anywhere in the code - it doesn't have to be in the same translation unit. For example:
```cpp
-CATCH_TRANSLATE_EXCEPTION( MyType& ex ) {
+CATCH_TRANSLATE_EXCEPTION( MyType const& ex ) {
return ex.message();
}
```
diff --git a/src/catch2/catch_translate_exception.hpp b/src/catch2/catch_translate_exception.hpp
index 0b5a3747..81021faa 100644
--- a/src/catch2/catch_translate_exception.hpp
+++ b/src/catch2/catch_translate_exception.hpp
@@ -12,7 +12,7 @@ namespace Catch {
class ExceptionTranslator : public IExceptionTranslator {
public:
- ExceptionTranslator( std::string(*translateFunction)( T& ) )
+ ExceptionTranslator( std::string(*translateFunction)( T const& ) )
: m_translateFunction( translateFunction )
{}
@@ -24,7 +24,7 @@ namespace Catch {
else
return (*it)->translate( it+1, itEnd );
}
- catch( T& ex ) {
+ catch( T const& ex ) {
return m_translateFunction( ex );
}
#else
@@ -33,12 +33,12 @@ namespace Catch {
}
protected:
- std::string(*m_translateFunction)( T& );
+ std::string(*m_translateFunction)( T const& );
};
public:
template<typename T>
- ExceptionTranslatorRegistrar( std::string(*translateFunction)( T& ) ) {
+ ExceptionTranslatorRegistrar( std::string(*translateFunction)( T const& ) ) {
getMutableRegistryHub().registerTranslator
( new ExceptionTranslator<T>( translateFunction ) );
}
diff --git a/tests/SelfTest/UsageTests/Exception.tests.cpp b/tests/SelfTest/UsageTests/Exception.tests.cpp
index f8c628b9..1f6b4fa2 100644
--- a/tests/SelfTest/UsageTests/Exception.tests.cpp
+++ b/tests/SelfTest/UsageTests/Exception.tests.cpp
@@ -122,15 +122,15 @@ TEST_CASE( "When unchecked exceptions are thrown, but caught, they do not affect
}
-CATCH_TRANSLATE_EXCEPTION( CustomException& ex ) {
+CATCH_TRANSLATE_EXCEPTION( CustomException const& ex ) {
return ex.getMessage();
}
-CATCH_TRANSLATE_EXCEPTION( CustomStdException& ex ) {
+CATCH_TRANSLATE_EXCEPTION( CustomStdException const& ex ) {
return ex.getMessage();
}
-CATCH_TRANSLATE_EXCEPTION( double& ex ) {
+CATCH_TRANSLATE_EXCEPTION( double const& ex ) {
return Catch::Detail::stringify( ex );
}