Source · fairmq/
Error.hpublic header
Defines struct fair::mq::ErrorCategory, struct fair::mq::RuntimeError.
Described in Handle errors and timeouts, Transfer codes and errors.
1/********************************************************************************2 * Copyright (C) 2021 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *3 * *4 * This software is distributed under the terms of the *5 * GNU Lesser General Public Licence (LGPL) version 3, *6 * copied verbatim in the file "LICENSE" *7 ********************************************************************************/8 9#ifndef FAIR_MQ_ERROR_H10#define FAIR_MQ_ERROR_H11 12#include <cassert>13#include <fairmq/tools/Strings.h>14#include <stdexcept>15#include <system_error>16 17// Macro copied from https://en.cppreference.com/w/cpp/error/assert18// Use (void) to silent unused warnings.19#define assertm(exp, msg) assert(((void)msg, exp))20 21namespace fair::mq {22 23struct RuntimeError : ::std::runtime_error24{25 template<typename... T>26 explicit RuntimeError(T&&... t)27 : ::std::runtime_error::runtime_error(tools::ToString(std::forward<T>(t)...))28 {}29};30 31enum class ErrorCode32{33 OperationInProgress = 10,34 OperationTimeout,35 OperationCanceled,36 DeviceChangeStateFailed,37 DeviceGetPropertiesFailed,38 DeviceSetPropertiesFailed39};40 41struct ErrorCategory : std::error_category42{43 const char* name() const noexcept override { return "fairmq"; }44 std::string message(int ev) const override45 {46 switch (static_cast<ErrorCode>(ev)) {47 case ErrorCode::OperationInProgress:48 return "async operation already in progress";49 case ErrorCode::OperationTimeout:50 return "async operation timed out";51 case ErrorCode::OperationCanceled:52 return "async operation canceled";53 case ErrorCode::DeviceChangeStateFailed:54 return "failed to change state of a fairmq device";55 case ErrorCode::DeviceGetPropertiesFailed:56 return "failed to get fairmq device properties";57 case ErrorCode::DeviceSetPropertiesFailed:58 return "failed to set fairmq device properties";59 default:60 return "(unrecognized error)";61 }62 }63};64 65static ErrorCategory ec;66 67inline std::error_code MakeErrorCode(ErrorCode e) { return {static_cast<int>(e), ec}; }68 69} // namespace fair::mq70 71namespace std {72 73template<>74struct is_error_code_enum<fair::mq::ErrorCode> : true_type75{};76 77} // namespace std78 79#endif /* FAIR_MQ_ERROR_H */