1 #ifndef _GLIBMM_ERROR_H
2 #define _GLIBMM_ERROR_H
3 
4 /* Copyright 2002 The gtkmm Development Team
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #include <glibmmconfig.h>
21 #include <glibmm/exception.h>
22 #include <glibmm/value.h>
23 #include <glib.h>
24 
25 namespace Glib
26 {
27 
28 class GLIBMM_API Error : public Glib::Exception
29 {
30 public:
31   Error();
32   Error(GQuark error_domain, int error_code, const Glib::ustring& message);
33   explicit Error(GError* gobject, bool take_copy = false);
34 
35   Error(const Error& other);
36   Error& operator=(const Error& other);
37 
38   ~Error() noexcept override;
39 
40   /** Test whether the %Error has an underlying instance.
41    *
42    * @newin{2,60}
43    */
44   explicit operator bool() const;
45 
46   GQuark domain() const;
47   int code() const;
48   Glib::ustring what() const override;
49 
50   bool matches(GQuark error_domain, int error_code) const;
51 
52   GError* gobj();
53   const GError* gobj() const;
54 
55 #ifndef DOXYGEN_SHOULD_SKIP_THIS
56 
57   void propagate(GError** dest);
58 
59   using ThrowFunc = void(*)(GError*);
60 
61   static void register_init();
62   static void register_cleanup();
63   static void register_domain(GQuark error_domain, ThrowFunc throw_func);
64 
65   static void throw_exception(GError* gobject) G_GNUC_NORETURN;
66 
67 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
68 
69 protected:
70   GError* gobject_;
71 };
72 
73 #ifndef DOXYGEN_SHOULD_SKIP_THIS
74 // This is needed so Glib::Error can be used with
75 // Glib::Value and _WRAP_PROPERTY.
76 template <>
77 class GLIBMM_API Value<Glib::Error> : public ValueBase_Boxed
78 {
79 public:
80   using CppType = Glib::Error;
81   using CType = GError*;
82 
83   static GType value_type();
84 
85   void set(const CppType& data);
86   CppType get() const;
87 };
88 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
89 
90 } // namespace Glib
91 
92 #endif /* _GLIBMM_ERROR_H */
93