Code_TYMPAN  4.4.0
Industrial site acoustic simulation
exceptions.h
Go to the documentation of this file.
1 
10 #ifndef TY_EXCEPTIONS
11 #define TY_EXCEPTIONS
12 
13 #include <string>
14 #include <sstream>
15 #include <cassert>
16 #include <exception>
17 #include <deque>
18 
19 #include <boost/exception/all.hpp>
20 #include <boost/current_function.hpp>
21 #include <boost/throw_exception.hpp>
22 #include <boost/config.hpp>
23 
24 // Beware : Stuff::operator<< must be defined in the same namespace as Stuff
25 
26 // For GTest related pretty-printing please see :
27 // http://code.google.com/p/googletest/wiki/AdvancedGuide#Teaching_Google_Test_How_to_Print_Your_Values
28 
29 // For boost::exception diagnostic please see:
30 // http://www.boost.org/doc/libs/1_54_0/libs/exception/doc/diagnostic_information.html
31 
32 template <typename T> std::string tympan_to_string(const T& o)
33 {
34  using namespace std;
35  stringstream ss;
36  ss << o;
37  return ss.str();
38 }
39 
40 namespace tympan
41 {
42 
43 // We use the boost::exception to add information to exception classes.
44 // Cf. http://www.boost.org/doc/libs/1_54_0/libs/exception/doc/tutorial_transporting_data.html
45 
47 struct exception : /* virtual std::exception,*/ virtual boost::exception
48 {
49 };
50 
52 struct logic_error : /*virtual*/ std::logic_error, virtual tympan::exception
53 {
54  logic_error() : std::logic_error("Code_TYMPAN internal logic error"){};
55  logic_error(const std::string& desc) : std::logic_error(desc){};
56 };
57 
59 struct invalid_data : /*virtual*/ std::runtime_error, virtual tympan::exception
60 {
61  invalid_data() : std::runtime_error("Code_TYMPAN invalid data encountered"){};
62  invalid_data(const std::string& desc) : std::runtime_error(desc){};
63 };
64 
65 /* NB : the commented-out virtual inheritance in logic_error and invalid_data is
66  * important : otherwise the classe derived from those would need to call the
67  * std::logic_error or std::runtime_error constructor.
68  * The point is std::logic_error and std::runtime_error inherits *non*-virtualy
69  * from std::exception, so that the inheritance of tympan::exception from
70  * has std::exception to be removed even if semantically it would be relevant.
71  */
72 
73 } // namespace tympan
74 
76 #define tympan_source_loc \
77  ::boost::throw_function(BOOST_CURRENT_FUNCTION) \
78  << ::boost::throw_file(__FILE__) << ::boost::throw_line((int)__LINE__)
79 
80 #endif // TY_EXCEPTIONS
std::stringstream ss
Definition: Logger.cpp:21
std::string tympan_to_string(const T &o)
Definition: exceptions.h:32
The base exception class for all exceptions specific to Code_TYMPAN.
Definition: exceptions.h:48
The base exception class for errors due to invalid data.
Definition: exceptions.h:60
invalid_data(const std::string &desc)
Definition: exceptions.h:62
The base exception class for internal logic / algorithmic errors.
Definition: exceptions.h:53
logic_error(const std::string &desc)
Definition: exceptions.h:55