Files
ugv_sdk/include/wrp_sdk/asyncio/device_error.hpp
2020-06-17 11:38:29 +08:00

58 lines
1.3 KiB
C++

/**
* @brief MAVConn device error class
* @file device_error.hpp
* @author Vladimir Ermakov <vooon341@gmail.com>
*/
/*
* libmavconn
* Copyright 2013,2014,2015,2016 Vladimir Ermakov, All rights reserved.
*
* This file is part of the mavros package and subject to the license terms
* in the top-level LICENSE file of the mavros repository.
* https://github.com/mavlink/mavros/tree/master/LICENSE.md
*/
#ifndef DEVICE_ERROR_HPP
#define DEVICE_ERROR_HPP
#include <string>
#include <cstring>
#include <stdexcept>
namespace westonrobot
{
class DeviceError : public std::runtime_error
{
public:
template <typename T>
DeviceError(const char *module, T msg) : std::runtime_error(make_message(module, msg))
{
}
template <typename T>
static std::string make_message(const char *module, T msg)
{
std::ostringstream ss;
ss << "DeviceError:" << module << ":" << msg_to_string(msg);
return ss.str();
}
static std::string msg_to_string(const char *description)
{
return description;
}
static std::string msg_to_string(int errnum)
{
return std::strerror(errnum);
}
static std::string msg_to_string(std::system_error &err)
{
return err.what();
}
};
} // namespace mavconn
#endif /* DEVICE_ERROR_HPP */