From 4b79f0047d4880207699c7c8df16472dc5342b81 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Sun, 7 Feb 2016 01:05:15 +0100 Subject: [PATCH] db/DatabaseError: add exception class DatabaseError --- src/command/CommandError.cxx | 4 ++++ src/db/DatabaseError.hxx | 14 ++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/src/command/CommandError.cxx b/src/command/CommandError.cxx index c3a726920..362797a39 100644 --- a/src/command/CommandError.cxx +++ b/src/command/CommandError.cxx @@ -179,6 +179,10 @@ ToAck(std::exception_ptr ep) return pe.GetCode(); } catch (const PlaylistError &pe) { return ToAck(pe.GetCode()); +#ifdef ENABLE_DATABASE + } catch (const DatabaseError &de) { + return ToAck(de.GetCode()); +#endif } catch (const std::system_error &e) { return ACK_ERROR_SYSTEM; #if defined(__GLIBCXX__) && __GLIBCXX__ < 20151204 diff --git a/src/db/DatabaseError.hxx b/src/db/DatabaseError.hxx index 3604ce862..acbe7aadc 100644 --- a/src/db/DatabaseError.hxx +++ b/src/db/DatabaseError.hxx @@ -20,6 +20,8 @@ #ifndef MPD_DB_ERROR_HXX #define MPD_DB_ERROR_HXX +#include + class Domain; enum class DatabaseErrorCode { @@ -34,6 +36,18 @@ enum class DatabaseErrorCode { CONFLICT, }; +class DatabaseError final : public std::runtime_error { + DatabaseErrorCode code; + +public: + DatabaseError(DatabaseErrorCode _code, const char *msg) + :std::runtime_error(msg), code(_code) {} + + DatabaseErrorCode GetCode() const { + return code; + } +}; + extern const Domain db_domain; #endif