2019-12-14 22:33:57 +01:00
|
|
|
//---
|
|
|
|
// fxos.errors: Exception specification
|
2020-02-28 16:19:50 +01:00
|
|
|
//
|
|
|
|
// 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)
|
2019-12-14 22:33:57 +01:00
|
|
|
//---
|
|
|
|
|
|
|
|
#ifndef LIBFXOS_ERRORS_H
|
|
|
|
#define LIBFXOS_ERRORS_H
|
|
|
|
|
2020-01-19 18:17:01 +01:00
|
|
|
#include <fxos/util.h>
|
2019-12-14 22:33:57 +01:00
|
|
|
#include <exception>
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
namespace FxOS {
|
|
|
|
|
2020-02-28 16:19:50 +01:00
|
|
|
/* Syntax errors for fxos data files. This is always an external error, and
|
|
|
|
reported to the user as an error message. */
|
2019-12-14 22:33:57 +01:00
|
|
|
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) {}
|
|
|
|
|
2020-01-19 18:17:01 +01:00
|
|
|
/* Provides access to these objects */
|
2019-12-14 22:33:57 +01:00
|
|
|
char const *file() const noexcept {
|
|
|
|
return m_file;
|
|
|
|
}
|
|
|
|
int line() const noexcept {
|
|
|
|
return m_line;
|
|
|
|
}
|
|
|
|
char const *what() const noexcept override {
|
|
|
|
return m_what;
|
|
|
|
}
|
|
|
|
|
2020-01-19 18:17:01 +01:00
|
|
|
/* Additional friendly formatter */
|
|
|
|
std::string str() const noexcept {
|
|
|
|
return format("%s:%d: %s", m_file, m_line, m_what);
|
|
|
|
}
|
|
|
|
|
2019-12-14 22:33:57 +01:00
|
|
|
private:
|
|
|
|
char const *m_file;
|
|
|
|
int m_line;
|
|
|
|
char const *m_what;
|
|
|
|
};
|
|
|
|
|
2020-02-28 16:19:50 +01:00
|
|
|
/* Language errors for the disassembler. These are either bugs in fxos or
|
|
|
|
caused by corrupted code files. */
|
2020-01-19 18:17:01 +01:00
|
|
|
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;
|
|
|
|
};
|
|
|
|
|
2020-02-12 07:53:00 +01:00
|
|
|
/* Address errors */
|
2020-02-28 16:19:50 +01:00
|
|
|
class AddressError: public std::exception
|
2020-02-12 07:53:00 +01:00
|
|
|
{
|
|
|
|
public:
|
2020-02-28 16:19:50 +01:00
|
|
|
static constexpr char const *default_message = "unmapped address";
|
|
|
|
|
|
|
|
AddressError(uint32_t address, int size,
|
|
|
|
char const *what = default_message):
|
2020-02-12 07:53:00 +01:00
|
|
|
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;
|
|
|
|
};
|
|
|
|
|
2020-02-28 16:19:50 +01:00
|
|
|
/* 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;
|
|
|
|
};
|
|
|
|
|
2019-12-14 22:33:57 +01:00
|
|
|
} /* namespace FxOS */
|
|
|
|
|
|
|
|
#endif /* LIBFXOS_ERRORS_H */
|