kopia lustrzana https://gitlab.com/sane-project/backends
genesys: Support message argument to exceptions
rodzic
72d68c7367
commit
9d07e2108a
|
@ -104,11 +104,42 @@
|
||||||
|
|
||||||
class SaneException : std::exception {
|
class SaneException : std::exception {
|
||||||
public:
|
public:
|
||||||
SaneException(SANE_Status status) : status_(status) {}
|
SaneException(SANE_Status status) : status_(status)
|
||||||
|
{
|
||||||
|
set_msg(nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
SaneException(SANE_Status status, const char* msg) : status_(status)
|
||||||
|
{
|
||||||
|
set_msg(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
SaneException(const char* msg) : SaneException(SANE_STATUS_INVAL, msg) {}
|
||||||
|
|
||||||
SANE_Status status() const { return status_; }
|
SANE_Status status() const { return status_; }
|
||||||
virtual const char* what() const noexcept override { return sane_strstatus(status_); }
|
virtual const char* what() const noexcept override { return msg_.c_str(); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
void set_msg(const char* msg)
|
||||||
|
{
|
||||||
|
const char* status_msg = sane_strstatus(status_);
|
||||||
|
std::size_t status_msg_len = std::strlen(status_msg);
|
||||||
|
|
||||||
|
if (msg) {
|
||||||
|
std::size_t msg_len = std::strlen(msg);
|
||||||
|
msg_.reserve(msg_len + status_msg_len + 3);
|
||||||
|
msg_ = msg;
|
||||||
|
msg_ += " : ";
|
||||||
|
msg_ += status_msg;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
msg_.reserve(status_msg_len);
|
||||||
|
msg_ = status_msg;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string msg_;
|
||||||
SANE_Status status_;
|
SANE_Status status_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Ładowanie…
Reference in New Issue