exception.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2014 Pavel Kirienko <pavel.kirienko@gmail.com>
3  */
4 
5 #pragma once
6 
7 #include <cerrno>
8 #include <cstring>
9 #include <stdexcept>
10 
11 namespace uavcan_linux
12 {
16 class Exception : public std::runtime_error
17 {
18  const int errno_;
19 
20  static std::string makeErrorString(const std::string& descr, int use_errno)
21  {
22  return descr + " [errno " + std::to_string(use_errno) + " \"" + std::strerror(use_errno) + "\"]";
23  }
24 
25 public:
26  explicit Exception(const std::string& descr, int use_errno = errno)
27  : std::runtime_error(makeErrorString(descr, use_errno))
28  , errno_(use_errno)
29  { }
30 
35  int getErrno() const { return errno_; }
36 };
37 
43 {
45 
46  static std::string makeErrorString(std::int16_t e)
47  {
48  return "Libuavcan error (" + std::to_string(e) + ")";
49  }
50 
51 public:
52  explicit LibuavcanErrorException(std::int16_t uavcan_error_code) :
53  Exception(makeErrorString(uavcan_error_code)),
54  error_(std::abs(uavcan_error_code))
55  { }
56 
57  std::int16_t getLibuavcanErrorCode() const { return error_; }
58 };
59 
64 {
65 public:
66  AllIfacesDownException() : Exception("All ifaces are down", ENETDOWN) { }
67 };
68 
69 }
Exception(const std::string &descr, int use_errno=errno)
Definition: exception.hpp:26
std::int16_t getLibuavcanErrorCode() const
Definition: exception.hpp:57
std::int16_t int16_t
Definition: std.hpp:30
static std::string makeErrorString(std::int16_t e)
Definition: exception.hpp:46
static std::string makeErrorString(const std::string &descr, int use_errno)
Definition: exception.hpp:20
LibuavcanErrorException(std::int16_t uavcan_error_code)
Definition: exception.hpp:52


uavcan_communicator
Author(s):
autogenerated on Wed Jan 11 2023 03:59:39