From 35d0d5b2eaad64a703f14e507746424d331d1c27 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Thu, 11 Apr 2013 13:57:35 +0200 Subject: [PATCH] exceptions: use const char* what() instead of String description() --- src/assert.cc | 2 +- src/client_manager.cc | 8 ++++---- src/exception.cc | 2 +- src/exception.hh | 10 +++++----- src/main.cc | 4 ++-- src/remote.cc | 2 +- 6 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/assert.cc b/src/assert.cc index 4bd51a04..0e316be8 100644 --- a/src/assert.cc +++ b/src/assert.cc @@ -13,7 +13,7 @@ struct assert_failed : logic_error assert_failed(const String& message) : m_message(message) {} - String description() const override { return m_message; } + const char* what() const override { return m_message.c_str(); } private: String m_message; }; diff --git a/src/client_manager.cc b/src/client_manager.cc index 006f4bed..b268df10 100644 --- a/src/client_manager.cc +++ b/src/client_manager.cc @@ -67,8 +67,8 @@ void ClientManager::create_client(std::unique_ptr&& ui, } catch (Kakoune::runtime_error& error) { - context->print_status({ error.description(), get_color("Error") }); - context->hooks().run_hook("RuntimeError", error.description(), *context); + context->print_status({ error.what(), get_color("Error") }); + context->hooks().run_hook("RuntimeError", error.what(), *context); } catch (Kakoune::client_removed&) { @@ -84,8 +84,8 @@ void ClientManager::create_client(std::unique_ptr&& ui, } catch (Kakoune::runtime_error& error) { - context->print_status({ error.description(), get_color("Error") }); - context->hooks().run_hook("RuntimeError", error.description(), *context); + context->print_status({ error.what(), get_color("Error") }); + context->hooks().run_hook("RuntimeError", error.what(), *context); } catch (Kakoune::client_removed&) { diff --git a/src/exception.cc b/src/exception.cc index 7f378b6c..2b8fedc0 100644 --- a/src/exception.cc +++ b/src/exception.cc @@ -7,7 +7,7 @@ namespace Kakoune { -String exception::description() const +const char* exception::what() const { return typeid(*this).name(); } diff --git a/src/exception.hh b/src/exception.hh index 0b68d39e..08647637 100644 --- a/src/exception.hh +++ b/src/exception.hh @@ -9,18 +9,18 @@ namespace Kakoune struct exception { virtual ~exception() {} - virtual String description() const; + virtual const char* what() const; }; struct runtime_error : exception { - runtime_error(const String& description) - : m_description(description) {} + runtime_error(String what) + : m_what(std::move(what)) {} - String description() const override { return m_description; } + const char* what() const override { return m_what.c_str(); } private: - String m_description; + String m_what; }; struct logic_error : exception diff --git a/src/main.cc b/src/main.cc index 97fc20b2..2bc487fc 100644 --- a/src/main.cc +++ b/src/main.cc @@ -986,7 +986,7 @@ int main(int argc, char* argv[]) } catch (Kakoune::runtime_error& error) { - write_debug("error while parsing kakrc: " + error.description()); + write_debug("error while parsing kakrc: "_str + error.what()); } if (parser.positional_count() != 0) @@ -1010,7 +1010,7 @@ int main(int argc, char* argv[]) } catch (Kakoune::exception& error) { - on_assert_failed(("uncaught exception:\n" + error.description()).c_str()); + on_assert_failed(("uncaught exception:\n"_str + error.what()).c_str()); return -1; } catch (std::exception& error) diff --git a/src/remote.cc b/src/remote.cc index ee80ebe3..8eb3c88b 100644 --- a/src/remote.cc +++ b/src/remote.cc @@ -450,7 +450,7 @@ private: } catch (runtime_error& e) { - write_debug("error running command '" + m_buffer + "' : " + e.description()); + write_debug("error running command '" + m_buffer + "' : " + e.what()); } ClientManager::instance().redraw_clients(); close(socket);