Arduino Filters master
Filter library for Arduino
Error.hpp
Go to the documentation of this file.
1#pragma once
2
4
6AH_DIAGNOSTIC_WERROR() // Enable errors on warnings
7
8#include <AH/Debug/Debug.hpp>
9
10#ifdef ARDUINO // ------------------------------------------------------ ARDUINO
11
13
16extern void fatalErrorExit() __attribute__((noreturn));
17
19
20#ifdef FATAL_ERRORS
21
22#define ERROR(msg, errc) \
23 do { \
24 USING_AH_NAMESPACE; \
25 DEBUGFN(msg << " (0x" << hex << uppercase << errc << dec \
26 << nouppercase << ')'); \
27 fatalErrorExit(); \
28 } while (0)
29
30#else
31
42#define ERROR(msg, errc) \
43 do { \
44 DEBUGFN(msg << " (0x" << hex << uppercase << errc << dec \
45 << nouppercase << ')'); \
46 } while (0)
47
48#endif
49
60#define FATAL_ERROR(msg, errc) \
61 do { \
62 USING_AH_NAMESPACE; \
63 DEBUGFN(F("Fatal Error: ") << msg << " (0x" << hex << uppercase \
64 << errc << dec << nouppercase << ')'); \
65 fatalErrorExit(); \
66 } while (0)
67
68#else // ----------------------------------------------------------------- TESTS
69
70#include <exception>
71#include <sstream>
72
74
75class ErrorException : public std::exception {
76 public:
77 ErrorException(const std::string message, int errorCode)
78 : message(std::move(message)), errorCode(errorCode) {}
79 const char *what() const throw() override { return message.c_str(); }
80 int getErrorCode() const { return errorCode; }
81
82 private:
83 const std::string message;
84 const int errorCode;
85};
86
88
89#define ERROR(msg, errc) \
90 do { \
91 USING_AH_NAMESPACE; \
92 std::ostringstream s; \
93 s << DEBUG_FUNC_LOCATION << msg; \
94 throw ErrorException(s.str(), errc); \
95 } while (0)
96
97#define FATAL_ERROR(msg, errc) \
98 do { \
99 USING_AH_NAMESPACE; \
100 std::ostringstream s; \
101 s << DEBUG_FUNC_LOCATION << msg; \
102 throw ErrorException(s.str(), errc); \
103 } while (0)
104
105#endif
106
void fatalErrorExit() __attribute__((noreturn))
Function that executes and loops forever, blinking the built-in LED when a fatal error is encountered...
Definition: Exit.cpp:10
#define END_AH_NAMESPACE
#define BEGIN_AH_NAMESPACE
#define AH_DIAGNOSTIC_POP()
Definition: Warnings.hpp:36
#define AH_DIAGNOSTIC_WERROR()
Definition: Warnings.hpp:35