#pragma once #include #include #include namespace raid { enum class ErrorCode { invalid_argument, data_quality, numerical, not_converged, unsupported, io, api, insufficient_samples, memory, cancelled }; constexpr std::string_view to_string(ErrorCode c) { switch (c) { case ErrorCode::invalid_argument: return "invalid_argument"; case ErrorCode::data_quality: return "data_quality"; case ErrorCode::numerical: return "numerical"; case ErrorCode::not_converged: return "not_converged"; case ErrorCode::unsupported: return "unsupported"; case ErrorCode::io: return "io"; case ErrorCode::api: return "api"; case ErrorCode::insufficient_samples: return "insufficient_samples"; case ErrorCode::memory: return "memory"; case ErrorCode::cancelled: return "cancelled"; } return "?"; } class RaidError : public std::runtime_error { public: RaidError(ErrorCode code, const std::string& msg) : std::runtime_error(std::string(to_string(code)) + ": " + msg), code_(code) {} ErrorCode code() const noexcept { return code_; } private: ErrorCode code_; }; #define RAID_REQUIRE(cond, code, msg) \ do { if (!(cond)) throw ::raid::RaidError(::raid::ErrorCode::code, std::string(msg) + " [" #cond "]"); } while (0) } // namespace raid