µOS++ IIIe Reference  v6.3.15
“Perfekt ist nicht gut genug”
The third edition of µOS++, a POSIX inspired open source system, written in C++.
system-error.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of the µOS++ distribution.
3  * (https://github.com/micro-os-plus)
4  * Copyright (c) 2016 Liviu Ionescu.
5  *
6  * Permission is hereby granted, free of charge, to any person
7  * obtaining a copy of this software and associated documentation
8  * files (the "Software"), to deal in the Software without
9  * restriction, including without limitation the rights to use,
10  * copy, modify, merge, publish, distribute, sublicense, and/or
11  * sell copies of the Software, and to permit persons to whom
12  * the Software is furnished to do so, subject to the following
13  * conditions:
14  *
15  * The above copyright notice and this permission notice shall be
16  * included in all copies or substantial portions of the Software.
17  *
18  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
20  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
22  * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
23  * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
25  * OTHER DEALINGS IN THE SOFTWARE.
26  */
27 
28 #include <cmsis-plus/rtos/os.h>
29 
30 #if defined(__EXCEPTIONS)
31 #include <string>
32 #include <system_error>
33 #endif
34 
35 // ----------------------------------------------------------------------------
36 
37 using namespace os;
38 
39 // ----------------------------------------------------------------------------
40 
41 namespace os
42 {
43  namespace estd
44  {
45  // ========================================================================
46 
47 #if defined(__EXCEPTIONS)
48 
49  struct system_error_category : public std::error_category
50  {
51  virtual const char*
52  name () const noexcept;
53 
54  virtual std::string
55  message (int i) const;
56 
57  };
58 
59  const char*
60  system_error_category::name () const noexcept
61  {
62  return "system";
63  }
64 
65 #pragma GCC diagnostic push
66 #pragma GCC diagnostic ignored "-Wunused-parameter"
67 
68  std::string
69  system_error_category::message (int i) const
70  {
71 #if defined(DEBUG)
72  return std::string (strerror (i));
73 #else
74  return std::string ("");
75 #endif
76  }
77 
78  struct cmsis_error_category : public std::error_category
79  {
80  virtual const char*
81  name () const noexcept;
82 
83  virtual std::string
84  message (int i) const;
85  };
86 
87  const char*
88  cmsis_error_category::name () const noexcept
89  {
90  return "cmsis";
91  }
92 
93 #pragma GCC diagnostic push
94 #pragma GCC diagnostic ignored "-Wunused-parameter"
95 
96  std::string
97  cmsis_error_category::message (int i) const
98  {
99 #if defined(DEBUG)
100  return std::string (strerror (i));
101 #else
102  return std::string ("");
103 #endif
104  }
105 
106 #pragma GCC diagnostic pop
107 
108 #endif
109 
110  void
111  __throw_system_error (int ev, const char* what_arg)
112  {
113 #if defined(__EXCEPTIONS)
114  throw std::system_error (std::error_code (ev, system_error_category ()),
115  what_arg);
116 #else
117  trace_printf ("system_error(%d, %s)\n", ev, what_arg);
118  std::abort ();
119 #endif
120  }
121 
122  void
123  __throw_cmsis_error (int ev, const char* what_arg)
124  {
125 #if defined(__EXCEPTIONS)
126  throw std::system_error (std::error_code (ev, cmsis_error_category ()),
127  what_arg);
128 #else
129  trace_printf ("system_error(%d, %s)\n", ev, what_arg);
130  std::abort ();
131 #endif
132  }
133 
134  // --------------------------------------------------------------------------
135 
136  } /* namespace estd */
137 } /* namespace os */
138 
139 // ----------------------------------------------------------------------------
Standard std namespace.
System namespace.
Single file µOS++ RTOS definitions.
void __throw_cmsis_error(int ev, const char *what_arg)
int trace_printf(const char *format,...)
void __throw_system_error(int ev, const char *what_arg)
void abort(void)
Definition: exit.c:52