5#ifndef LINE_UTIL_ERROR_H
6#define LINE_UTIL_ERROR_H
46 if (s.empty())
return false;
47 auto alpha = [](
char c) {
return (c >=
'A' && c <=
'Z') || (c >=
'a' && c <=
'z'); };
48 auto digit = [](
char c) {
return c >=
'0' && c <=
'9'; };
49 if (!alpha(s[0]))
return false;
51 if (!alpha(c) && !digit(c) && c !=
'_')
return false;
56inline std::string
make_id(
const char* category,
const std::string& kind) {
57 if (!
valid_kind(kind))
return "LINE:internal:BadErrorId";
58 return std::string(
"LINE:") + category +
":" + kind;
73class Error :
public std::runtime_error {
75 explicit Error(
const std::string& what) : std::runtime_error(what), id_(
"LINE:Error") {}
78 const std::string&
id() const noexcept {
return id_; }
82 const std::size_t a = id_.find(
':');
83 const std::size_t b = id_.find(
':', a + 1);
84 return b == std::string::npos ? std::string() : id_.substr(a + 1, b - a - 1);
89 const std::size_t a = id_.find(
':');
90 const std::size_t b = id_.find(
':', a + 1);
91 return b == std::string::npos ? std::string() : id_.substr(b + 1);
Error(const char *category, const std::string &kind, const std::string &what)
const std::string & id() const noexcept
The full identifier, e.g.
Error(const std::string &what)
std::string category() const
unsupported, numerical, input, external, internal, or empty for LINE:Error.
std::string kind() const
The <kind> part, or empty for LINE:Error.
ExternalError(const std::string &what)
ExternalError(const ErrorKind &kind, const std::string &what)
InternalError(const ErrorKind &kind, const std::string &what)
InternalError(const std::string &what)
NumericError(const ErrorKind &kind, const std::string &what)
NumericError(const std::string &what)
UnsupportedError(const ErrorKind &kind, const std::string &what)
UnsupportedError(const std::string &what)
bool valid_kind(const std::string &s)
True when s matches [A-Za-z][A-Za-z0-9_]*, the grammar of a kind.
std::string make_id(const char *category, const std::string &kind)
LINE:<category>:<kind>, or LINE:internal:BadErrorId for a malformed kind.
Conservation laws of a layered queueing network, enumerated from its structure.
The <kind> part of a LINE:<category>:<kind> identifier (see _kb/17-error-vocabulary....