From 2747c4dd3ecd6169873545cea4832fa79b0c73a1 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Fri, 13 Mar 2015 13:15:51 +0000 Subject: [PATCH] exception::what returns a StringView rather than a const char* --- src/assert.cc | 2 +- src/client.cc | 2 +- src/client_manager.cc | 2 +- src/exception.cc | 2 +- src/exception.hh | 4 ++-- src/main.cc | 10 +++++----- 6 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/assert.cc b/src/assert.cc index 74b939a4..1edf1e45 100644 --- a/src/assert.cc +++ b/src/assert.cc @@ -19,7 +19,7 @@ struct assert_failed : logic_error assert_failed(String message) : m_message(std::move(message)) {} - const char* what() const override { return m_message.c_str(); } + StringView what() const override { return m_message; } private: String m_message; }; diff --git a/src/client.cc b/src/client.cc index ae18ebe4..dcd575b8 100644 --- a/src/client.cc +++ b/src/client.cc @@ -79,7 +79,7 @@ void Client::handle_available_input(EventMode mode) } 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()); } catch (Kakoune::client_removed&) diff --git a/src/client_manager.cc b/src/client_manager.cc index b1b97888..974be41f 100644 --- a/src/client_manager.cc +++ b/src/client_manager.cc @@ -41,7 +41,7 @@ Client* ClientManager::create_client(std::unique_ptr&& ui, } 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()); } diff --git a/src/exception.cc b/src/exception.cc index 2b8fedc0..e97f2b6c 100644 --- a/src/exception.cc +++ b/src/exception.cc @@ -7,7 +7,7 @@ namespace Kakoune { -const char* exception::what() const +StringView exception::what() const { return typeid(*this).name(); } diff --git a/src/exception.hh b/src/exception.hh index 08647637..fd29017c 100644 --- a/src/exception.hh +++ b/src/exception.hh @@ -9,7 +9,7 @@ namespace Kakoune struct exception { virtual ~exception() {} - virtual const char* what() const; + virtual StringView what() const; }; struct runtime_error : exception @@ -17,7 +17,7 @@ struct runtime_error : exception runtime_error(String 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: String m_what; diff --git a/src/main.cc b/src/main.cc index 88ea11a0..bb17dc83 100644 --- a/src/main.cc +++ b/src/main.cc @@ -307,7 +307,7 @@ int run_client(StringView session, StringView init_command) } catch (connection_failed& e) { - fputs(e.what(), stderr); + fputs(e.what().zstr(), stderr); return -1; } return 0; @@ -448,7 +448,7 @@ int run_filter(StringView keystr, ConstArrayView files, bool quiet) { if (not quiet) 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 files, bool quiet) } 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(); @@ -497,7 +497,7 @@ int run_pipe(StringView session) } catch (connection_failed& e) { - fputs(e.what(), stderr); + fputs(e.what().zstr(), stderr); return -1; } return 0; @@ -592,7 +592,7 @@ int main(int argc, char* argv[]) printf("Error: %s\n" "Valid switches:\n" "%s", - error.what(), + (const char*)error.what().zstr(), generate_switches_doc(param_desc.switches).c_str()); return -1; }