• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *  Created by Martin on 01/08/2017.
3  *
4  *  Distributed under the Boost Software License, Version 1.0. (See accompanying
5  *  file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6  */
7 #ifndef TWOBLUECUBES_CATCH_ENFORCE_H_INCLUDED
8 #define TWOBLUECUBES_CATCH_ENFORCE_H_INCLUDED
9 
10 #include "catch_common.h"
11 #include "catch_compiler_capabilities.h"
12 #include "catch_stream.h"
13 
14 
15 #include <stdexcept>
16 
17 namespace Catch {
18 #if !defined(CATCH_CONFIG_DISABLE_EXCEPTIONS)
19     template <typename Ex>
20     [[noreturn]]
throw_exception(Ex const & e)21     void throw_exception(Ex const& e) {
22         throw e;
23     }
24 #else // ^^ Exceptions are enabled //  Exceptions are disabled vv
25     [[noreturn]]
26     void throw_exception(std::exception const& e);
27 #endif
28 } // namespace Catch;
29 
30 #define CATCH_PREPARE_EXCEPTION( type, msg ) \
31     type( ( Catch::ReusableStringStream() << msg ).str() )
32 #define CATCH_INTERNAL_ERROR( msg ) \
33     Catch::throw_exception(CATCH_PREPARE_EXCEPTION( std::logic_error, CATCH_INTERNAL_LINEINFO << ": Internal Catch error: " << msg))
34 #define CATCH_ERROR( msg ) \
35     Catch::throw_exception(CATCH_PREPARE_EXCEPTION( std::domain_error, msg ))
36 #define CATCH_RUNTIME_ERROR( msg ) \
37     Catch::throw_exception(CATCH_PREPARE_EXCEPTION( std::runtime_error, msg ))
38 #define CATCH_ENFORCE( condition, msg ) \
39     do{ if( !(condition) ) CATCH_ERROR( msg ); } while(false)
40 
41 
42 #endif // TWOBLUECUBES_CATCH_ENFORCE_H_INCLUDED
43