//--- // fxos.errors: Exception specification // // fxos uses the following exception classes when reporting errors. // // Fatal errors (caught by main): // std::logic_error Internal consistency, fxos is broken // FxOS::LimitError fxos doesn't know how to handle the input // FxOS::LangError Program is invalid or dabatase too poor // // Recoverable errors: // std::runtime_error External errors (fi. file access) // FxOS::SyntaxError Invalid fxos data file syntax (file is skipped) // FxOS::AddressError Invalid virtual address (not bound) //--- #ifndef LIBFXOS_ERRORS_H #define LIBFXOS_ERRORS_H #include #include #include namespace FxOS { /* Syntax errors for fxos data files. This is always an external error, and reported to the user as an error message. */ class SyntaxError: public std::exception { public: /* Specifies the file and line of the exception */ SyntaxError(char const *file, int line, char const *what): m_file(file), m_line(line), m_what(what) {} /* Provides access to these objects */ char const *file() const noexcept { return m_file; } int line() const noexcept { return m_line; } char const *what() const noexcept override { return m_what; } /* Additional friendly formatter */ std::string str() const noexcept { return format("%s:%d: %s", m_file, m_line, m_what); } private: char const *m_file; int m_line; char const *m_what; }; /* Language errors for the disassembler. These are either bugs in fxos or caused by corrupted code files. */ class LangError: public std::exception { public: LangError(uint32_t address, char const *what): m_addr(address), m_what(what) {} uint32_t addr() const noexcept { return m_addr; } char const *what() const noexcept override { return m_what; } private: uint32_t m_addr; char const *m_what; }; /* Address errors */ class AddressError: public std::exception { public: static constexpr char const *default_message = "unmapped address"; AddressError(uint32_t address, int size, char const *what = default_message): m_addr(address), m_size(size), m_what(what) {} uint32_t addr() const noexcept { return m_addr; } int size() const noexcept { return m_size; } char const *what() const noexcept override { return m_what; } private: uint32_t m_addr; int m_size; char const *m_what; }; /* Limitations of fxos */ class LimitError: public std::exception { public: LimitError(char const *what): m_what(what) {} char const *what() const noexcept override { return m_what; } private: char const *m_what; }; } /* namespace FxOS */ #endif /* LIBFXOS_ERRORS_H */