diff options
author | Kjell Ahlstedt <kjellahlstedt@gmail.com> | 2019-12-14 12:31:39 +0100 |
---|---|---|
committer | Kjell Ahlstedt <kjellahlstedt@gmail.com> | 2019-12-14 12:31:39 +0100 |
commit | 2f4a122fa05e9e6514f62112d75d1ee7e4d894f2 (patch) | |
tree | df45a9a00fa204b7a09a3189b16600bd87c7bfc1 | |
parent | 729b1ae95d5d05b78741eeef1d635f95b19d790b (diff) | |
download | glibmm-2f4a122fa05e9e6514f62112d75d1ee7e4d894f2.tar.gz |
Derive Glib::Error from std::exception, remove Glib::Exception
Glib::Error::what() returns const char* (was Glib::ustring). It overrides
std::exception::what() that returns const char* and is noexcept.
Fixes #23
-rw-r--r-- | glib/glibmm.h | 1 | ||||
-rw-r--r-- | glib/glibmm/error.cc | 6 | ||||
-rw-r--r-- | glib/glibmm/error.h | 6 | ||||
-rw-r--r-- | glib/glibmm/exception.cc | 39 | ||||
-rw-r--r-- | glib/glibmm/exception.h | 36 | ||||
-rw-r--r-- | glib/glibmm/filelist.am | 2 | ||||
-rw-r--r-- | tests/giomm_ioerror/main.cc | 4 | ||||
-rw-r--r-- | tests/giomm_memoryinputstream/main.cc | 2 | ||||
-rw-r--r-- | tests/giomm_simple/main.cc | 2 |
9 files changed, 10 insertions, 88 deletions
diff --git a/glib/glibmm.h b/glib/glibmm.h index a7587d17..93e3a4ff 100644 --- a/glib/glibmm.h +++ b/glib/glibmm.h @@ -99,7 +99,6 @@ #include <glibmm/dispatcher.h> #include <glibmm/enums.h> #include <glibmm/error.h> -#include <glibmm/exception.h> #include <glibmm/exceptionhandler.h> #include <glibmm/fileutils.h> #include <glibmm/interface.h> diff --git a/glib/glibmm/error.cc b/glib/glibmm/error.cc index 68c20e18..c8e22fc3 100644 --- a/glib/glibmm/error.cc +++ b/glib/glibmm/error.cc @@ -50,7 +50,7 @@ Error::Error(GError* gobject, bool take_copy) } Error::Error(const Error& other) -: Exception(other), gobject_((other.gobject_) ? g_error_copy(other.gobject_) : nullptr) +: std::exception(other), gobject_((other.gobject_) ? g_error_copy(other.gobject_) : nullptr) { } @@ -99,8 +99,8 @@ Error::code() const return gobject_->code; } -Glib::ustring -Error::what() const +const char* +Error::what() const noexcept { g_return_val_if_fail(gobject_ != nullptr, ""); g_return_val_if_fail(gobject_->message != nullptr, ""); diff --git a/glib/glibmm/error.h b/glib/glibmm/error.h index 5f49ee26..32e3a60c 100644 --- a/glib/glibmm/error.h +++ b/glib/glibmm/error.h @@ -18,14 +18,14 @@ */ #include <glibmmconfig.h> -#include <glibmm/exception.h> #include <glibmm/value.h> #include <glib.h> +#include <exception> namespace Glib { -class Error : public Glib::Exception +class Error : public std::exception { public: Error(); @@ -45,7 +45,7 @@ public: GQuark domain() const; int code() const; - Glib::ustring what() const override; + const char* what() const noexcept override; bool matches(GQuark error_domain, int error_code) const; diff --git a/glib/glibmm/exception.cc b/glib/glibmm/exception.cc deleted file mode 100644 index 2c25ea9c..00000000 --- a/glib/glibmm/exception.cc +++ /dev/null @@ -1,39 +0,0 @@ -/* exception.cc - * - * Copyright 2002 The gtkmm Development Team - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library. If not, see <http://www.gnu.org/licenses/>. - */ - -//#include <glib/gtestutils.h> //For g_assert() in glib >= 2.15.0 -//#include <glib/gmessages.h> //For g_assert() in glib < 2.15.0 -#include <glib.h> //For g_assert() in all versions of glib. - -#include <glibmm/exception.h> - -namespace Glib -{ - -Exception::~Exception() noexcept -{ -} - -Glib::ustring -Exception::what() const -{ - g_assert_not_reached(); - return Glib::ustring(); -} - -} // namespace Glib diff --git a/glib/glibmm/exception.h b/glib/glibmm/exception.h deleted file mode 100644 index 726f39e0..00000000 --- a/glib/glibmm/exception.h +++ /dev/null @@ -1,36 +0,0 @@ -#ifndef _GLIBMM_EXCEPTION_H -#define _GLIBMM_EXCEPTION_H - -/* exception.h - * - * Copyright 2002 The gtkmm Development Team - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library. If not, see <http://www.gnu.org/licenses/>. - */ - -#include <glibmm/ustring.h> - -namespace Glib -{ - -class Exception -{ -public: - virtual ~Exception() noexcept = 0; - virtual Glib::ustring what() const = 0; -}; - -} // namespace Glib - -#endif /* _GLIBMM_EXCEPTION_H */ diff --git a/glib/glibmm/filelist.am b/glib/glibmm/filelist.am index 530c439f..e606d5fd 100644 --- a/glib/glibmm/filelist.am +++ b/glib/glibmm/filelist.am @@ -9,7 +9,6 @@ glibmm_files_extra_cc = \ debug.cc \ dispatcher.cc \ error.cc \ - exception.cc \ exceptionhandler.cc \ extraclassinit.cc \ init.cc \ @@ -42,7 +41,6 @@ glibmm_files_extra_h = \ debug.h \ dispatcher.h \ error.h \ - exception.h \ exceptionhandler.h \ extraclassinit.h \ i18n-lib.h \ diff --git a/tests/giomm_ioerror/main.cc b/tests/giomm_ioerror/main.cc index 8aaa4298..de312f8a 100644 --- a/tests/giomm_ioerror/main.cc +++ b/tests/giomm_ioerror/main.cc @@ -73,9 +73,9 @@ main(int, char**) else std::cerr << "Gio::Error exception caught: " << ex.what() << std::endl; } - catch (const Glib::Exception& ex) + catch (const Glib::Error& ex) { - std::cerr << "Exception caught: " << ex.what() << std::endl; + std::cerr << "Glib::Error exception caught: " << ex.what() << std::endl; return EXIT_FAILURE; } diff --git a/tests/giomm_memoryinputstream/main.cc b/tests/giomm_memoryinputstream/main.cc index ce1b54ec..cbf682fb 100644 --- a/tests/giomm_memoryinputstream/main.cc +++ b/tests/giomm_memoryinputstream/main.cc @@ -77,7 +77,7 @@ main(int, char**) return EXIT_FAILURE; } } - catch (const Glib::Exception& ex) + catch (const Glib::Error& ex) { std::cerr << "Exception caught: " << ex.what() << std::endl; return EXIT_FAILURE; diff --git a/tests/giomm_simple/main.cc b/tests/giomm_simple/main.cc index 7b1e8767..0a73cb51 100644 --- a/tests/giomm_simple/main.cc +++ b/tests/giomm_simple/main.cc @@ -49,7 +49,7 @@ main(int, char**) return EXIT_FAILURE; } } - catch (const Glib::Exception& ex) + catch (const Glib::Error& ex) { std::cerr << "Exception caught: " << ex.what() << std::endl; return EXIT_FAILURE; |