fxos/include/fxos/errors.h

89 lines
1.6 KiB
C++

//---
// fxos.errors: Exception specification
//---
#ifndef LIBFXOS_ERRORS_H
#define LIBFXOS_ERRORS_H
#include <fxos/util.h>
#include <exception>
#include <string>
namespace FxOS {
/* Syntax errors for fxos data files */
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 */
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 AddrError: public std::exception
{
public:
AddrError(uint32_t address, int size, char const *what):
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;
};
} /* namespace FxOS */
#endif /* LIBFXOS_ERRORS_H */