Crocoddyl
Loading...
Searching...
No Matches
exception.hpp
1
2// BSD 3-Clause License
3//
4// Copyright (C) 2019-2023, University of Edinburgh, LAAS-CNRS,
5// Heriot-Watt University
6// Copyright note valid unless otherwise stated in individual files.
7// All rights reserved.
9
10#ifndef CROCODDYL_CORE_UTILS_EXCEPTION_HPP_
11#define CROCODDYL_CORE_UTILS_EXCEPTION_HPP_
12
13#include <exception>
14#include <sstream>
15
16#define NOEXCEPT noexcept
17
18#ifndef throw_pretty
19#define throw_pretty(m) \
20 { \
21 std::stringstream ss; \
22 ss << m; \
23 throw crocoddyl::Exception(ss.str(), __FILE__, __PRETTY_FUNCTION__, \
24 __LINE__); \
25 }
26#endif
27
28#ifndef NDEBUG
29#ifndef assert_pretty
30#define assert_pretty(condition, m) \
31 if (!(condition)) { \
32 std::stringstream ss; \
33 ss << m; \
34 throw crocoddyl::Exception(ss.str(), __FILE__, __PRETTY_FUNCTION__, \
35 __LINE__); \
36 }
37#endif
38#else
39#ifndef assert_pretty
40#define assert_pretty(condition, m) ((void)0)
41#endif
42#endif
43namespace crocoddyl {
44
45class Exception : public std::exception {
46 public:
47 explicit Exception(const std::string& msg, const char* file, const char* func,
48 int line);
49 virtual ~Exception() NOEXCEPT;
50 virtual const char* what() const NOEXCEPT;
51
52 std::string getMessage() const;
53 std::string getExtraData() const;
54
55 private:
56 std::string exception_msg_;
57 std::string extra_data_;
58 std::string msg_;
59};
60
61} // namespace crocoddyl
62
63#endif // CROCODDYL_CORE_UTILS_EXCEPTION_HPP_