MotionLib  1.0.0
SamBuCa motion library
Exception.hpp
1 /*
2  * Copyright (C) 2021 CERN
3  *
4  * This software is provided 'as-is', without any express or implied
5  * warranty. In no event will the authors be held liable for any damages
6  * arising from the use of this software.
7  *
8  * Permission is granted to anyone to use this software for any purpose,
9  * including commercial applications, and to alter it and redistribute it
10  * freely, subject to the following restrictions:
11  *
12  * 1. The origin of this software must not be misrepresented; you must not
13  * claim that you wrote the original software. If you use this software
14  * in a product, an acknowledgment in the product documentation would be
15  * appreciated but is not required.
16  * 2. Altered source versions must be plainly marked as such, and must not be
17  * misrepresented as being the original software.
18  * 3. This notice may not be removed or altered from any source distribution.
19  *
20  * Created on: 2021-11-17
21  * Author: Michal Mysior <mmysior> <michal.mysior@cern.ch>
22  *
23  */
24 
25 #ifndef MOTION_CONTROLLER_EXCEPTION_HPP__
26 #define MOTION_CONTROLLER_EXCEPTION_HPP__
27 
28 #include <cerrno>
29 #include <exception>
30 #include <system_error>
31 
32 namespace smc {
43 enum class ErrorCode
44 {
45  Ok = 0,
46  InvalidArguments = EINVAL, /*< invalid argument */
47  IO = EIO, /*< io error */
48  Canceled = ECANCELED, /*< operation aborted */
49  Runtime = EFAULT, /*< runtime error */
50  NotSupported = ENOTSUP, /*< Operation not supported */
51 
52  InternalError = 1000, /*< internal error */
53  IncompatibleUnits, /*< incompatible units */
54 };
55 
60 class Exception : public std::exception
61 {
62 public:
63  Exception() = delete;
64  explicit Exception(std::error_code ev);
65  Exception(std::error_code ev, const std::string &what);
66 
67  inline const std::error_code getErrorCode() const noexcept
68  {
69  return m_errorCode;
70  }
71 
72  const char *what() const noexcept override;
73 
74 private:
75  const std::error_code m_errorCode;
76  mutable std::string m_what;
77 };
78 
79 std::error_code make_error_code(smc::ErrorCode);
80 
81 Exception make_errno_exception(std::error_code ev);
82 
85 } /* namespace smc */
86 
87 namespace std {
88 
89 template<>
90 struct is_error_code_enum<smc::ErrorCode> : true_type
91 {};
92 
93 } /* namespace std */
94 
95 #endif /* MOTION_CONTROLLER_EXCEPTION_HPP__ */
Exception thrown by MotionController in case of issues with command.
Definition: Exception.hpp:61
ErrorCode
Error related to MotionController.
Definition: Exception.hpp:44
main motion-lib namespace
Definition: Client.cpp:30