From 1c90400081c5f265964d03555f1fa6707ea614dc Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Sun, 27 Dec 2015 06:43:55 +0100 Subject: [PATCH] command/Error: pass std::exception_ptr to PrintError() Necessary to preserve type information. The try/catch sequence didn't work previously. --- src/command/AllCommands.cxx | 2 +- src/command/CommandError.cxx | 17 ++++++++++++----- src/command/CommandError.hxx | 4 ++-- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/command/AllCommands.cxx b/src/command/AllCommands.cxx index 8cc8f40c5..6e2af39fa 100644 --- a/src/command/AllCommands.cxx +++ b/src/command/AllCommands.cxx @@ -418,6 +418,6 @@ try { return ret; } catch (const std::exception &e) { Response r(client, num); - PrintError(r, e); + PrintError(r, std::current_exception()); return CommandResult::ERROR; } diff --git a/src/command/CommandError.cxx b/src/command/CommandError.cxx index 73d2060e7..27295000a 100644 --- a/src/command/CommandError.cxx +++ b/src/command/CommandError.cxx @@ -159,19 +159,26 @@ print_error(Response &r, const Error &error) } void -PrintError(Response &r, const std::exception &e) +PrintError(Response &r, std::exception_ptr ep) { - LogError(e); + try { + std::rethrow_exception(ep); + } catch (const std::exception &e) { + LogError(e); + } catch (...) { + } try { - throw e; + std::rethrow_exception(ep); } catch (const ProtocolError &pe) { r.Error(pe.GetCode(), pe.what()); } catch (const PlaylistError &pe) { r.Error(ToAck(pe.GetCode()), pe.what()); - } catch (const std::system_error &) { + } catch (const std::system_error &e) { r.Error(ACK_ERROR_SYSTEM, e.what()); - } catch (...) { + } catch (const std::exception &e) { r.Error(ACK_ERROR_UNKNOWN, e.what()); + } catch (...) { + r.Error(ACK_ERROR_UNKNOWN, "Unknown error"); } } diff --git a/src/command/CommandError.hxx b/src/command/CommandError.hxx index 5fc547339..4fb1bf8bc 100644 --- a/src/command/CommandError.hxx +++ b/src/command/CommandError.hxx @@ -24,7 +24,7 @@ #include "PlaylistError.hxx" namespace std { - class exception; + class exception_ptr; } class Response; @@ -40,6 +40,6 @@ CommandResult print_error(Response &r, const Error &error); void -PrintError(Response &r, const std::exception &e); +PrintError(Response &r, std::exception_ptr ep); #endif