Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: UAVCAN UAVCAN_Subscriber
exception.hpp
00001 /* 00002 * Copyright (C) 2014 Pavel Kirienko <pavel.kirienko@gmail.com> 00003 */ 00004 00005 #pragma once 00006 00007 #include <cerrno> 00008 #include <cstring> 00009 #include <stdexcept> 00010 00011 namespace uavcan_linux 00012 { 00013 /** 00014 * This is the root exception class for all exceptions that can be thrown from the libuavcan Linux driver. 00015 */ 00016 class Exception : public std::runtime_error 00017 { 00018 const int errno_; 00019 00020 static std::string makeErrorString(const std::string& descr, int use_errno) 00021 { 00022 return descr + " [errno " + std::to_string(use_errno) + " \"" + std::strerror(use_errno) + "\"]"; 00023 } 00024 00025 public: 00026 explicit Exception(const std::string& descr, int use_errno = errno) 00027 : std::runtime_error(makeErrorString(descr, use_errno)) 00028 , errno_(use_errno) 00029 { } 00030 00031 /** 00032 * Returns standard UNIX errno value captured at the moment 00033 * when this exception object was constructed. 00034 */ 00035 int getErrno() const { return errno_; } 00036 }; 00037 00038 /** 00039 * This type is thrown when a Libuavcan API method exits with error. 00040 * The error code is stored in the exception object and is avialable via @ref getLibuavcanErrorCode(). 00041 */ 00042 class LibuavcanErrorException : public Exception 00043 { 00044 const std::int16_t error_; 00045 00046 static std::string makeErrorString(std::int16_t e) 00047 { 00048 return "Libuavcan error (" + std::to_string(e) + ")"; 00049 } 00050 00051 public: 00052 explicit LibuavcanErrorException(std::int16_t uavcan_error_code) : 00053 Exception(makeErrorString(uavcan_error_code)), 00054 error_(std::abs(uavcan_error_code)) 00055 { } 00056 00057 std::int16_t getLibuavcanErrorCode() const { return error_; } 00058 }; 00059 00060 /** 00061 * This exception is thrown when all available interfaces become down. 00062 */ 00063 class AllIfacesDownException : public Exception 00064 { 00065 public: 00066 AllIfacesDownException() : Exception("All ifaces are down", ENETDOWN) { } 00067 }; 00068 00069 }
Generated on Tue Jul 12 2022 17:17:31 by
1.7.2