[gtkmm] Gtk::PaperSize: Throw exception from a constructor
- From: Kjell Ahlstedt <kjellahl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtkmm] Gtk::PaperSize: Throw exception from a constructor
- Date: Tue, 11 Jul 2017 08:28:16 +0000 (UTC)
commit d868182595f5e791400f13c0faf16f0eabf51453
Author: Kjell Ahlstedt <kjellahlstedt gmail com>
Date: Tue Jul 11 10:25:01 2017 +0200
Gtk::PaperSize: Throw exception from a constructor
The constructor that reads from a Glib::KeyFile can fail. If it does,
throw an exception instead of creating an invalid PaperSize instance.
gtk/src/papersize.ccg | 13 ++++++++-----
gtk/src/papersize.hg | 8 ++++++++
2 files changed, 16 insertions(+), 5 deletions(-)
---
diff --git a/gtk/src/papersize.ccg b/gtk/src/papersize.ccg
index 9cd04fd..f157fd0 100644
--- a/gtk/src/papersize.ccg
+++ b/gtk/src/papersize.ccg
@@ -57,12 +57,15 @@ PaperSize::PaperSize(const Glib::ustring& name, const Glib::ustring& display_nam
GtkUnit(unit)))
{}
-//TODO: Add an operator bool() so we can detect if this succeeded:
-//TODO: No, throw the error/exception instead.
PaperSize::PaperSize(const Glib::KeyFile& key_file, const Glib::ustring& group_name)
-:
- gobject_(gtk_paper_size_new_from_key_file(const_cast<GKeyFile*>(key_file.gobj()), (group_name.empty() ?
nullptr : group_name.c_str()) , nullptr /* GError */))
-{}
+{
+ GError* gerror = nullptr;
+ gobject_ = gtk_paper_size_new_from_key_file(const_cast<GKeyFile*>(key_file.gobj()),
+ Glib::c_str_or_nullptr(group_name), &gerror);
+
+ if (gerror)
+ Glib::Error::throw_exception(gerror);
+}
bool PaperSize::equal(const PaperSize& other) const
{
diff --git a/gtk/src/papersize.hg b/gtk/src/papersize.hg
index db20a95..d423213 100644
--- a/gtk/src/papersize.hg
+++ b/gtk/src/papersize.hg
@@ -63,6 +63,14 @@ public:
explicit PaperSize(const Glib::ustring& ppd_name, const Glib::ustring& ppd_display_name, double width,
double height);
explicit PaperSize(const Glib::ustring& name, const Glib::ustring& display_name, double width, double
height, Unit unit);
+ /** Reads a paper size from the group @a group_name in the key file @a key_file.
+ *
+ * @param key_file The Glib::KeyFile to retrieve the paper size from.
+ * @param group_name The name of the group in the key file to read,
+ * or an empty string to read the first group.
+ *
+ * @throws Gtk::PrintError, Glib::KeyFileError
+ */
explicit PaperSize(const Glib::KeyFile& key_file, const Glib::ustring& group_name = Glib::ustring());
_IGNORE(gtk_paper_size_copy, gtk_paper_size_free, gtk_paper_size_is_equal)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]