exceptions: use const char* what() instead of String description()

This commit is contained in:
Maxime Coste 2013-04-11 13:57:35 +02:00
parent c699172110
commit 35d0d5b2ea
6 changed files with 14 additions and 14 deletions

View File

@ -13,7 +13,7 @@ struct assert_failed : logic_error
assert_failed(const String& message) assert_failed(const String& message)
: m_message(message) {} : m_message(message) {}
String description() const override { return m_message; } const char* what() const override { return m_message.c_str(); }
private: private:
String m_message; String m_message;
}; };

View File

@ -67,8 +67,8 @@ void ClientManager::create_client(std::unique_ptr<UserInterface>&& ui,
} }
catch (Kakoune::runtime_error& error) catch (Kakoune::runtime_error& error)
{ {
context->print_status({ error.description(), get_color("Error") }); context->print_status({ error.what(), get_color("Error") });
context->hooks().run_hook("RuntimeError", error.description(), *context); context->hooks().run_hook("RuntimeError", error.what(), *context);
} }
catch (Kakoune::client_removed&) catch (Kakoune::client_removed&)
{ {
@ -84,8 +84,8 @@ void ClientManager::create_client(std::unique_ptr<UserInterface>&& ui,
} }
catch (Kakoune::runtime_error& error) catch (Kakoune::runtime_error& error)
{ {
context->print_status({ error.description(), get_color("Error") }); context->print_status({ error.what(), get_color("Error") });
context->hooks().run_hook("RuntimeError", error.description(), *context); context->hooks().run_hook("RuntimeError", error.what(), *context);
} }
catch (Kakoune::client_removed&) catch (Kakoune::client_removed&)
{ {

View File

@ -7,7 +7,7 @@
namespace Kakoune namespace Kakoune
{ {
String exception::description() const const char* exception::what() const
{ {
return typeid(*this).name(); return typeid(*this).name();
} }

View File

@ -9,18 +9,18 @@ namespace Kakoune
struct exception struct exception
{ {
virtual ~exception() {} virtual ~exception() {}
virtual String description() const; virtual const char* what() const;
}; };
struct runtime_error : exception struct runtime_error : exception
{ {
runtime_error(const String& description) runtime_error(String what)
: m_description(description) {} : m_what(std::move(what)) {}
String description() const override { return m_description; } const char* what() const override { return m_what.c_str(); }
private: private:
String m_description; String m_what;
}; };
struct logic_error : exception struct logic_error : exception

View File

@ -986,7 +986,7 @@ int main(int argc, char* argv[])
} }
catch (Kakoune::runtime_error& error) 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) if (parser.positional_count() != 0)
@ -1010,7 +1010,7 @@ int main(int argc, char* argv[])
} }
catch (Kakoune::exception& error) 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; return -1;
} }
catch (std::exception& error) catch (std::exception& error)

View File

@ -450,7 +450,7 @@ private:
} }
catch (runtime_error& e) 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(); ClientManager::instance().redraw_clients();
close(socket); close(socket);