1
0
forked from cheng/wallet
wallet/src/ILog.h

93 lines
2.8 KiB
C
Raw Normal View History

#pragma once
extern int errorCode;
extern std::string szError;
void ILogFatalError(const char*);
void ILogError(const char*);
void ILogWarning(const char*);
void ILogMessage(const char* format);
void ILogVerbose(const char*);
void ILogDebug(const char*);
void queue_error_message(const char*); //Used for error conditions within a destructor because you cannot throw within a destructor
void queue_fatal_error(const char*); //Used for fatal error conditions within a destructor in place of FatalException because you cannot throw within a destructor
struct sqlite3;
class MyException: public std::exception {
private:
std::string err;
int err_number;
public:
virtual ~MyException() override = default;
MyException() = delete;
explicit MyException(const std::string &m) noexcept :err(m.c_str()),err_number(-1){}
explicit MyException(const char* sz) noexcept :err(sz),err_number(-1) {}
explicit MyException(const char* sz, int i) noexcept :err(sz), err_number(i) {}
explicit MyException(const char* sz, int i, const char*, const char*) noexcept;
// usage throw MyException("error", __LINE__, __func__, __FILE__);
explicit MyException(int, sqlite3*) noexcept;
virtual const char* what() const override {
return err.c_str();
}
virtual const int what_num() const {
return err_number;
}
};
class FatalException : public MyException {
public:
using MyException::MyException;
FatalException() noexcept;
};
class HashReuseException : public MyException {
public:
using MyException::MyException;
HashReuseException() noexcept;
};
class NonUtf8DataInDatabase : public MyException {
public:
using MyException::MyException;
NonUtf8DataInDatabase() noexcept;
};
class BadDataException : public MyException {
public:
using MyException::MyException;
BadDataException() noexcept;
};
class NonRandomScalarException : public MyException {
public:
using MyException::MyException;
NonRandomScalarException() noexcept;
};
class BadScalarException : public MyException {
public:
using MyException::MyException;
BadScalarException() noexcept;
};
class OversizeBase58String : public MyException {
public:
using MyException::MyException;
OversizeBase58String() noexcept;
};
// This exception is obviously far too generic, because the routine throwing it knows nothing of the context.
// does not know what the cryptographic id identifies.
// higher level code that does know the context needs to catch the exception and issue a more
// relevant errror message, possibly with by more informative rethrow.
class BadStringRepresentationOfCryptoIdException : public MyException {
public:
using MyException::MyException;
BadStringRepresentationOfCryptoIdException() noexcept;
};
class NotBase58Exception : public MyException {
public:
using MyException::MyException;
NotBase58Exception() noexcept;
};