mirror of https://github.com/djcb/mu.git
mu-error: Better support for GError
Allow filling a GError from a Mu::Error
This commit is contained in:
parent
80cbf7c75b
commit
dce924da9c
|
@ -22,6 +22,7 @@
|
||||||
|
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include "mu-utils.hh"
|
#include "mu-utils.hh"
|
||||||
|
#include "mu-util.h"
|
||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
|
|
||||||
namespace Mu {
|
namespace Mu {
|
||||||
|
@ -69,7 +70,7 @@ struct Error final : public std::exception {
|
||||||
}
|
}
|
||||||
|
|
||||||
Error(Error&& rhs) = default;
|
Error(Error&& rhs) = default;
|
||||||
Error(const Error& rhs) = delete;
|
Error(const Error& rhs) = default;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Build an error from a GError an error-code and a format string
|
* Build an error from a GError an error-code and a format string
|
||||||
|
@ -118,7 +119,18 @@ struct Error final : public std::exception {
|
||||||
*/
|
*/
|
||||||
Code code() const { return code_; }
|
Code code() const { return code_; }
|
||||||
|
|
||||||
private:
|
|
||||||
|
/**
|
||||||
|
* Fill a GError with the error information
|
||||||
|
*
|
||||||
|
* @param err GError** (or NULL)
|
||||||
|
*/
|
||||||
|
void fill_g_error(GError **err) {
|
||||||
|
g_set_error(err, MU_ERROR_DOMAIN, static_cast<int>(code_),
|
||||||
|
"%s", what_.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
const Code code_;
|
const Code code_;
|
||||||
std::string what_;
|
std::string what_;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue