exception::what returns a StringView rather than a const char*

This commit is contained in:
Maxime Coste 2015-03-13 13:15:51 +00:00
parent 52cd08915d
commit 2747c4dd3e
6 changed files with 11 additions and 11 deletions

View File

@ -19,7 +19,7 @@ struct assert_failed : logic_error
assert_failed(String message) assert_failed(String message)
: m_message(std::move(message)) {} : m_message(std::move(message)) {}
const char* what() const override { return m_message.c_str(); } StringView what() const override { return m_message; }
private: private:
String m_message; String m_message;
}; };

View File

@ -79,7 +79,7 @@ void Client::handle_available_input(EventMode mode)
} }
catch (Kakoune::runtime_error& error) catch (Kakoune::runtime_error& error)
{ {
context().print_status({ error.what(), get_face("Error") }); context().print_status({ error.what().str(), get_face("Error") });
context().hooks().run_hook("RuntimeError", error.what(), context()); context().hooks().run_hook("RuntimeError", error.what(), context());
} }
catch (Kakoune::client_removed&) catch (Kakoune::client_removed&)

View File

@ -41,7 +41,7 @@ Client* ClientManager::create_client(std::unique_ptr<UserInterface>&& ui,
} }
catch (Kakoune::runtime_error& error) catch (Kakoune::runtime_error& error)
{ {
client->context().print_status({ error.what(), get_face("Error") }); client->context().print_status({ error.what().str(), get_face("Error") });
client->context().hooks().run_hook("RuntimeError", error.what(), client->context().hooks().run_hook("RuntimeError", error.what(),
client->context()); client->context());
} }

View File

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

View File

@ -9,7 +9,7 @@ namespace Kakoune
struct exception struct exception
{ {
virtual ~exception() {} virtual ~exception() {}
virtual const char* what() const; virtual StringView what() const;
}; };
struct runtime_error : exception struct runtime_error : exception
@ -17,7 +17,7 @@ struct runtime_error : exception
runtime_error(String what) runtime_error(String what)
: m_what(std::move(what)) {} : m_what(std::move(what)) {}
const char* what() const override { return m_what.c_str(); } StringView what() const override { return m_what.c_str(); }
private: private:
String m_what; String m_what;

View File

@ -307,7 +307,7 @@ int run_client(StringView session, StringView init_command)
} }
catch (connection_failed& e) catch (connection_failed& e)
{ {
fputs(e.what(), stderr); fputs(e.what().zstr(), stderr);
return -1; return -1;
} }
return 0; return 0;
@ -448,7 +448,7 @@ int run_filter(StringView keystr, ConstArrayView<StringView> files, bool quiet)
{ {
if (not quiet) if (not quiet)
fprintf(stderr, "error while applying keys to buffer '%s': %s\n", fprintf(stderr, "error while applying keys to buffer '%s': %s\n",
buffer.display_name().c_str(), err.what()); buffer.display_name().c_str(), (const char*)err.what().zstr());
} }
}; };
@ -471,7 +471,7 @@ int run_filter(StringView keystr, ConstArrayView<StringView> files, bool quiet)
} }
catch (Kakoune::runtime_error& err) catch (Kakoune::runtime_error& err)
{ {
fprintf(stderr, "error: %s\n", err.what()); fprintf(stderr, "error: %s\n", (const char*)err.what().zstr());
} }
buffer_manager.clear_buffer_trash(); buffer_manager.clear_buffer_trash();
@ -497,7 +497,7 @@ int run_pipe(StringView session)
} }
catch (connection_failed& e) catch (connection_failed& e)
{ {
fputs(e.what(), stderr); fputs(e.what().zstr(), stderr);
return -1; return -1;
} }
return 0; return 0;
@ -592,7 +592,7 @@ int main(int argc, char* argv[])
printf("Error: %s\n" printf("Error: %s\n"
"Valid switches:\n" "Valid switches:\n"
"%s", "%s",
error.what(), (const char*)error.what().zstr(),
generate_switches_doc(param_desc.switches).c_str()); generate_switches_doc(param_desc.switches).c_str());
return -1; return -1;
} }