mu-error: Better support for GError

Allow filling a GError from a Mu::Error
This commit is contained in:
Dirk-Jan C. Binnema 2022-02-15 22:28:21 +02:00
parent 80cbf7c75b
commit dce924da9c
1 changed files with 14 additions and 2 deletions

View File

@ -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_;
}; };