µOS++ IIIe Reference 7.0.0
The third edition of µOS++, a POSIX inspired open source framework, written in C++
Loading...
Searching...
No Matches
system-error.cpp
Go to the documentation of this file.
1/*
2 * This file is part of the µOS++ project (https://micro-os-plus.github.io/).
3 * Copyright (c) 2016-2025 Liviu Ionescu. All rights reserved.
4 *
5 * Permission to use, copy, modify, and/or distribute this software
6 * for any purpose is hereby granted, under the terms of the MIT license.
7 *
8 * If a copy of the license was not distributed with this file, it can
9 * be obtained from https://opensource.org/licenses/mit.
10 */
11
12#include <cmsis-plus/rtos/os.h>
13
14#if defined(__EXCEPTIONS)
15#include <string>
16#include <system_error>
17#endif
18
19// ----------------------------------------------------------------------------
20
21#if defined(__clang__)
22#pragma clang diagnostic ignored "-Wc++98-compat"
23#pragma clang diagnostic ignored "-Wc++98-compat-bind-to-temporary-copy"
24#endif
25
26// ----------------------------------------------------------------------------
27
28using namespace os;
29
30// ----------------------------------------------------------------------------
31
32namespace os
33{
34 namespace estd
35 {
36 // ========================================================================
37
38#if defined(__EXCEPTIONS)
39
40 struct system_error_category : public std::error_category
41 {
42 virtual const char*
43 name () const noexcept override;
44
45 virtual std::string
46 message (int i) const override;
47 };
48
49 const char*
50 system_error_category::name () const noexcept
51 {
52 return "system";
53 }
54
55#pragma GCC diagnostic push
56#if defined(__clang__)
57#pragma clang diagnostic ignored "-Wunused-parameter"
58#elif defined(__GNUC__)
59#pragma GCC diagnostic ignored "-Wunused-parameter"
60#endif
61
62 std::string
63 system_error_category::message (int i) const
64 {
65#if defined(DEBUG)
66 return std::string (strerror (i));
67#else
68 return std::string ("");
69#endif
70 }
71
72 struct cmsis_error_category : public std::error_category
73 {
74 virtual const char*
75 name () const noexcept override;
76
77 virtual std::string
78 message (int i) const override;
79 };
80
81 const char*
82 cmsis_error_category::name () const noexcept
83 {
84 return "cmsis";
85 }
86
87#pragma GCC diagnostic push
88#if defined(__clang__)
89#pragma clang diagnostic ignored "-Wunused-parameter"
90#elif defined(__GNUC__)
91#pragma GCC diagnostic ignored "-Wunused-parameter"
92#endif
93
94 std::string
95 cmsis_error_category::message (int i) const
96 {
97#if defined(DEBUG)
98 return std::string (strerror (i));
99#else
100 return std::string ("");
101#endif
102 }
103
104#pragma GCC diagnostic pop
105
106#endif
107
108 void
109 __throw_system_error (int ev, const char* what_arg)
110 {
111#if defined(__EXCEPTIONS)
112 // error: copying parameter of type 'os::estd::system_error_category'
113 // when binding a reference to a temporary would invoke a deleted
114 // constructor in C++98 [-Werror,-Wc++98-compat-bind-to-temporary-copy]
115 throw std::system_error (std::error_code (ev, system_error_category ()),
116 what_arg);
117#else
118 trace_printf ("system_error(%d, %s)\n", ev, what_arg);
119 std::abort ();
120#endif
121 }
122
123 void
124 __throw_cmsis_error (int ev, const char* what_arg)
125 {
126#if defined(__EXCEPTIONS)
127 // error: copying parameter of type 'os::estd::cmsis_error_category' when
128 // binding a reference to a temporary would invoke a deleted constructor
129 // in C++98 [-Werror,-Wc++98-compat-bind-to-temporary-copy]
130 throw std::system_error (std::error_code (ev, cmsis_error_category ()),
131 what_arg);
132#else
133 trace_printf ("system_error(%d, %s)\n", ev, what_arg);
134 std::abort ();
135#endif
136 }
137
138 // ------------------------------------------------------------------------
139
140 } /* namespace estd */
141} /* namespace os */
142
143// ----------------------------------------------------------------------------
void __throw_system_error(int ev, const char *what_arg)
void __throw_cmsis_error(int ev, const char *what_arg)
System namespace.
Standard std namespace.
Single file µOS++ RTOS definitions.
int trace_printf(const char *format,...)