Dynotree
Loading...
Searching...
No Matches
dynotree_macros.h
Go to the documentation of this file.
1#pragma once
2
3#include <iostream>
4#include <sstream>
5#include <stdexcept>
6#include <string>
7#include <vector>
8
9namespace dynotree {
10
11class pretty_runtime_exception : public std::runtime_error {
12 // Adapted from:
13 // https://stackoverflow.com/questions/348833/how-to-know-the-exact-line-of-code-where-an-exception-has-been-caused
14
15public:
16 pretty_runtime_exception(const std::string &arg, const char *file, int line,
17 const char *function)
18 : std::runtime_error(arg) {
19 std::ostringstream o;
20 o << "Error in " << function << " (" << file << ":" << line << "): " << arg
21 << std::endl;
22 msg = o.str();
23 }
24
26 const char *what() const throw() { return msg.c_str(); }
27
28private:
29 std::string msg;
30};
31} // namespace dynotree
32
33#define THROW_PRETTY_DYNOTREE(arg) \
34 throw pretty_runtime_exception(arg, __FILE__, __LINE__, __FUNCTION__);
35
36#define CHECK_PRETTY_DYNOTREE(condition, arg) \
37 if (!(condition)) { \
38 throw pretty_runtime_exception(arg, __FILE__, __LINE__, __FUNCTION__); \
39 }
40
41#define CHECK_PRETTY_DYNOTREE__(condition) \
42 if (!(condition)) { \
43 throw pretty_runtime_exception(#condition, __FILE__, __LINE__, \
44 __FUNCTION__); \
45 }
46
47#define MESSAGE_PRETTY_DYNOTREE(arg) \
48 std::cout << "Message in " << __FUNCTION__ << " (" << __FILE__ << ":" \
49 << __LINE__ << ") --" << arg << std::endl;
Definition dynotree_macros.h:11
~pretty_runtime_exception()
Definition dynotree_macros.h:25
const char * what() const
Definition dynotree_macros.h:26
pretty_runtime_exception(const std::string &arg, const char *file, int line, const char *function)
Definition dynotree_macros.h:16
Definition dynotree_macros.h:9