From 3118966598aaa8d80bc7e34aaa3d7cc1658ef694 Mon Sep 17 00:00:00 2001 From: Chris Frey Date: Tue, 10 Jan 2012 01:02:31 -0500 Subject: [PATCH] lib: added new exception (ClearError) for when library cannot erase a database Sometimes databases are read-only and the error code is specific in this regard (often an error code 2). It is helpful to make this explicit with its own exception, so that Restore code can check for this case and deal with it alone. --- doc/Exceptions | 1 + src/error.h | 25 +++++++++++++++++++++++++ src/m_desktop.cc | 2 +- 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/doc/Exceptions b/doc/Exceptions index 3c26c4f8..f340c9b9 100644 --- a/doc/Exceptions +++ b/doc/Exceptions @@ -22,6 +22,7 @@ The Barry library has the following exception hierarchy: - Barry::JDWP::Error - Barry::JDWP::Timeout - Barry::PinNotFound + - Barry::ClearError Usb::Error All specific USB error exceptions will be derived from diff --git a/src/error.h b/src/error.h index e44707e0..65930180 100644 --- a/src/error.h +++ b/src/error.h @@ -265,6 +265,31 @@ public: RestoreError(const std::string &str) : Error(str) {} }; +// +// ClearError +// +/// Thrown by the Mode::Desktop class when ClearDatabase() fails. +/// The packet command and return code are passed along, for examination +/// by application code. Note that return code 0x02 usually means +/// you're trying to clear a read-only database, like Time Zones. +/// +class BXEXPORT ClearError : public Barry::Error +{ + unsigned int m_command, m_return_code; + +public: + ClearError(const std::string &str, unsigned int command, + unsigned int return_code) + : Error(str) + , m_command(command) + , m_return_code(return_code) + { + } + + unsigned int command() const { return m_command; } + unsigned int return_code() const { return m_return_code; } +}; + /// @} } // namespace Barry diff --git a/src/m_desktop.cc b/src/m_desktop.cc index 44c57a71..e44f1908 100644 --- a/src/m_desktop.cc +++ b/src/m_desktop.cc @@ -413,7 +413,7 @@ void Desktop::ClearDatabase(unsigned int dbId) oss << "Desktop: could not clear database: (command: " << "0x" << std::hex << packet.Command() << ", code: " << "0x" << std::hex << packet.ReturnCode() << ")"; - throw Error(oss.str()); + throw ClearError(oss.str(), packet.Command(), packet.ReturnCode()); } // check response to clear command was successful -- 2.11.4.GIT