blockchain_db: factor some exception code

Ideally, the log would go in the exception's ctor, but
two log levels are used, so I'd need to specify the level
in the ctor, which isn't great as it's not really related
to the exception.
This commit is contained in:
moneromooo-monero 2014-12-06 21:21:17 +00:00 committed by warptangent
parent e285ee5aec
commit 10fd6cab6c

View File

@ -139,15 +139,16 @@ typedef std::pair<crypto::hash, uint64_t> tx_out_index;
/*********************************** /***********************************
* Exception Definitions * Exception Definitions
***********************************/ ***********************************/
class DB_ERROR : public std::exception class DB_EXCEPTION : public std::exception
{ {
private: private:
std::string m; std::string m;
public:
DB_ERROR() : m("Generic DB Error") { }
DB_ERROR(const char* s) : m(s) { }
virtual ~DB_ERROR() { } protected:
DB_EXCEPTION(const char *s) : m(s) { }
public:
virtual ~DB_EXCEPTION() { }
const char* what() const throw() const char* what() const throw()
{ {
@ -155,196 +156,95 @@ class DB_ERROR : public std::exception
} }
}; };
class DB_OPEN_FAILURE : public std::exception class DB_ERROR : public DB_EXCEPTION
{ {
private:
std::string m;
public: public:
DB_OPEN_FAILURE() : m("Failed to open the db") { } DB_ERROR() : DB_EXCEPTION("Generic DB Error") { }
DB_OPEN_FAILURE(const char* s) : m(s) { } DB_ERROR(const char* s) : DB_EXCEPTION(s) { }
virtual ~DB_OPEN_FAILURE() { }
const char* what() const throw()
{
return m.c_str();
}
}; };
class DB_CREATE_FAILURE : public std::exception class DB_OPEN_FAILURE : public DB_EXCEPTION
{ {
private:
std::string m;
public: public:
DB_CREATE_FAILURE() : m("Failed to create the db") { } DB_OPEN_FAILURE() : DB_EXCEPTION("Failed to open the db") { }
DB_CREATE_FAILURE(const char* s) : m(s) { } DB_OPEN_FAILURE(const char* s) : DB_EXCEPTION(s) { }
virtual ~DB_CREATE_FAILURE() { }
const char* what() const throw()
{
return m.c_str();
}
}; };
class DB_SYNC_FAILURE : public std::exception class DB_CREATE_FAILURE : public DB_EXCEPTION
{ {
private:
std::string m;
public: public:
DB_SYNC_FAILURE() : m("Failed to sync the db") { } DB_CREATE_FAILURE() : DB_EXCEPTION("Failed to create the db") { }
DB_SYNC_FAILURE(const char* s) : m(s) { } DB_CREATE_FAILURE(const char* s) : DB_EXCEPTION(s) { }
virtual ~DB_SYNC_FAILURE() { }
const char* what() const throw()
{
return m.c_str();
}
}; };
class BLOCK_DNE : public std::exception class DB_SYNC_FAILURE : public DB_EXCEPTION
{ {
private:
std::string m;
public: public:
BLOCK_DNE() : m("The block requested does not exist") { } DB_SYNC_FAILURE() : DB_EXCEPTION("Failed to sync the db") { }
BLOCK_DNE(const char* s) : m(s) { } DB_SYNC_FAILURE(const char* s) : DB_EXCEPTION(s) { }
virtual ~BLOCK_DNE() { }
const char* what() const throw()
{
return m.c_str();
}
}; };
class BLOCK_PARENT_DNE : public std::exception class BLOCK_DNE : public DB_EXCEPTION
{ {
private:
std::string m;
public: public:
BLOCK_PARENT_DNE() : m("The parent of the block does not exist") { } BLOCK_DNE() : DB_EXCEPTION("The block requested does not exist") { }
BLOCK_PARENT_DNE(const char* s) : m(s) { } BLOCK_DNE(const char* s) : DB_EXCEPTION(s) { }
virtual ~BLOCK_PARENT_DNE() { }
const char* what() const throw()
{
return m.c_str();
}
}; };
class BLOCK_EXISTS : public std::exception class BLOCK_PARENT_DNE : public DB_EXCEPTION
{ {
private:
std::string m;
public: public:
BLOCK_EXISTS() : m("The block to be added already exists!") { } BLOCK_PARENT_DNE() : DB_EXCEPTION("The parent of the block does not exist") { }
BLOCK_EXISTS(const char* s) : m(s) { } BLOCK_PARENT_DNE(const char* s) : DB_EXCEPTION(s) { }
virtual ~BLOCK_EXISTS() { }
const char* what() const throw()
{
return m.c_str();
}
}; };
class BLOCK_INVALID : public std::exception class BLOCK_EXISTS : public DB_EXCEPTION
{ {
private:
std::string m;
public: public:
BLOCK_INVALID() : m("The block to be added did not pass validation!") { } BLOCK_EXISTS() : DB_EXCEPTION("The block to be added already exists!") { }
BLOCK_INVALID(const char* s) : m(s) { } BLOCK_EXISTS(const char* s) : DB_EXCEPTION(s) { }
virtual ~BLOCK_INVALID() { }
const char* what() const throw()
{
return m.c_str();
}
}; };
class TX_DNE : public std::exception class BLOCK_INVALID : public DB_EXCEPTION
{ {
private:
std::string m;
public: public:
TX_DNE() : m("The transaction requested does not exist") { } BLOCK_INVALID() : DB_EXCEPTION("The block to be added did not pass validation!") { }
TX_DNE(const char* s) : m(s) { } BLOCK_INVALID(const char* s) : DB_EXCEPTION(s) { }
virtual ~TX_DNE() { }
const char* what() const throw()
{
return m.c_str();
}
}; };
class TX_EXISTS : public std::exception class TX_DNE : public DB_EXCEPTION
{ {
private:
std::string m;
public: public:
TX_EXISTS() : m("The transaction to be added already exists!") { } TX_DNE() : DB_EXCEPTION("The transaction requested does not exist") { }
TX_EXISTS(const char* s) : m(s) { } TX_DNE(const char* s) : DB_EXCEPTION(s) { }
virtual ~TX_EXISTS() { }
const char* what() const throw()
{
return m.c_str();
}
}; };
class OUTPUT_DNE : public std::exception class TX_EXISTS : public DB_EXCEPTION
{ {
private:
std::string m;
public: public:
OUTPUT_DNE() : m("The output requested does not exist!") { } TX_EXISTS() : DB_EXCEPTION("The transaction to be added already exists!") { }
OUTPUT_DNE(const char* s) : m(s) { } TX_EXISTS(const char* s) : DB_EXCEPTION(s) { }
virtual ~OUTPUT_DNE() { }
const char* what() const throw()
{
return m.c_str();
}
}; };
class OUTPUT_EXISTS : public std::exception class OUTPUT_DNE : public DB_EXCEPTION
{ {
private:
std::string m;
public: public:
OUTPUT_EXISTS() : m("The output to be added already exists!") { } OUTPUT_DNE() : DB_EXCEPTION("The output requested does not exist!") { }
OUTPUT_EXISTS(const char* s) : m(s) { } OUTPUT_DNE(const char* s) : DB_EXCEPTION(s) { }
virtual ~OUTPUT_EXISTS() { }
const char* what() const throw()
{
return m.c_str();
}
}; };
class KEY_IMAGE_EXISTS : public std::exception class OUTPUT_EXISTS : public DB_EXCEPTION
{ {
private:
std::string m;
public: public:
KEY_IMAGE_EXISTS() : m("The spent key image to be added already exists!") { } OUTPUT_EXISTS() : DB_EXCEPTION("The output to be added already exists!") { }
KEY_IMAGE_EXISTS(const char* s) : m(s) { } OUTPUT_EXISTS(const char* s) : DB_EXCEPTION(s) { }
};
virtual ~KEY_IMAGE_EXISTS() { } class KEY_IMAGE_EXISTS : public DB_EXCEPTION
{
const char* what() const throw() public:
{ KEY_IMAGE_EXISTS() : DB_EXCEPTION("The spent key image to be added already exists!") { }
return m.c_str(); KEY_IMAGE_EXISTS(const char* s) : DB_EXCEPTION(s) { }
}
}; };
/*********************************** /***********************************