Control Surface main
MIDI Control Surface library for Arduino
Loading...
Searching...
No Matches
Error.hpp
Go to the documentation of this file.
1#pragma once
2
4
5#include <AH/Debug/Debug.hpp>
6
7#ifdef ARDUINO // ------------------------------------------------------ ARDUINO
8
10
13extern void fatalErrorExit() __attribute__((noreturn));
14
16
17#ifdef FATAL_ERRORS
18
19#define ERROR(msg, errc) \
20 do { \
21 USING_AH_NAMESPACE; \
22 DEBUGFN(msg << " (0x" << hex << uppercase << errc << dec \
23 << nouppercase << ')'); \
24 fatalErrorExit(); \
25 } while (0)
26
27#else
28
39#define ERROR(msg, errc) \
40 do { \
41 DEBUGFN(msg << " (0x" << hex << uppercase << errc << dec \
42 << nouppercase << ')'); \
43 } while (0)
44
45#endif
46
57#define FATAL_ERROR(msg, errc) \
58 do { \
59 USING_AH_NAMESPACE; \
60 DEBUGFN(F("Fatal Error: ") << msg << " (0x" << hex << uppercase \
61 << errc << dec << nouppercase << ')'); \
62 fatalErrorExit(); \
63 } while (0)
64
65#else // ----------------------------------------------------------------- TESTS
66
67#include <exception>
68#include <sstream>
69
71
72class ErrorException : public std::exception {
73 public:
74 ErrorException(const std::string message, int errorCode)
75 : message(std::move(message)), errorCode(errorCode) {}
76 const char *what() const throw() override { return message.c_str(); }
77 int getErrorCode() const { return errorCode; }
78
79 private:
80 const std::string message;
81 const int errorCode;
82};
83
85
86#define ERROR(msg, errc) \
87 do { \
88 USING_AH_NAMESPACE; \
89 std::ostringstream s; \
90 s << DEBUG_FUNC_LOCATION << msg; \
91 throw ErrorException(s.str(), errc); \
92 } while (0)
93
94#define FATAL_ERROR(msg, errc) \
95 do { \
96 USING_AH_NAMESPACE; \
97 std::ostringstream s; \
98 s << DEBUG_FUNC_LOCATION << msg; \
99 throw ErrorException(s.str(), errc); \
100 } while (0)
101
102#endif
#define END_AH_NAMESPACE
#define BEGIN_AH_NAMESPACE
void fatalErrorExit() __attribute__((noreturn))
Function that executes and loops forever, blinking the built-in LED when a fatal error is encountered...
Definition Exit.cpp:7