2022-02-16 00:53:01 -05:00
# 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
2023-02-25 09:05:53 -05:00
struct sqlite3 ;
2022-02-16 00:53:01 -05:00
class MyException : public std : : exception {
private :
std : : string err ;
2023-02-25 09:05:53 -05:00
int err_number ;
2022-02-16 00:53:01 -05:00
public :
virtual ~ MyException ( ) override = default ;
MyException ( ) = delete ;
2023-02-25 09:05:53 -05:00
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 ) { }
2023-09-16 04:49:43 -04:00
explicit MyException ( const char * sz , int i , const char * , const char * ) noexcept ;
// usage throw MyException("error", __LINE__, __func__, __FILE__);
2023-02-25 09:05:53 -05:00
explicit MyException ( int , sqlite3 * ) noexcept ;
2022-02-16 00:53:01 -05:00
virtual const char * what ( ) const override {
return err . c_str ( ) ;
}
2023-02-25 09:05:53 -05:00
virtual const int what_num ( ) const {
return err_number ;
}
2022-02-16 00:53:01 -05:00
} ;
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 ;
} ;