2.2.8. Error.h

This file contains the functionality used for reporting errors. In the description of the exceptions we use the standard terminology (see e.g., Exception Safety). If nothing else is specified a thrown exception from MØD provides no exception safety. Any exception thrown from MØD or any dependencies are intented to derive from std::exception, and any exception from MØD derives from Exception. The exceptions are in general only thrown from the outer-most interface, and not from within the mod::lib namespace.

2.2.8.1. Class Stacktrace

class Stacktrace

A class encapsulating the current stacktrace at construction time. Stacktraces may not be supported on all platforms.

2.2.8.1.1. Synopsis

struct Stacktrace {
    Stacktrace(unsigned int frameLimit, unsigned int numSkip);
    void print(unsigned int frameLimit, std::ostream &s) const;
private:
    std::vector<std::string> raw;
    std::vector<std::string> demangled;
};

2.2.8.1.2. Details

Stacktrace(unsigned int frameLimit, unsigned int numSkip)

Capture a stacktrace with at most frameLimit frames and without the first numSkip frames. The frame from the constructor it self is always skipped.

void print(unsigned int frameLimit, std::ostream &s) const

Print at most the first frameLimit frames from the capture stacktrace. Use 0 to print all available frames. Symbol names will be demangled if possible.

2.2.8.2. Class Exception

class Exception : public std::exception

The base class of all MØD exceptions.

2.2.8.2.1. Synopsis

struct Exception : public std::exception {
protected:
    Exception(std::string &&text, unsigned int numSkip, unsigned int frameLimit) : text(text), stacktrace(frameLimit, numSkip) { }
    Exception(std::string &&text, unsigned int numSkip) : Exception(std::move(text), numSkip, 20) { }
    Exception(std::string &&text) : Exception(std::move(text), 0) { }
public:
    virtual std::string getName() const = 0;
    virtual const char *what() const noexcept;
    void printStacktrace(unsigned int frameLimit, std::ostream &s) const;
protected:
    std::string text;
    Stacktrace stacktrace;
    mutable std::string whatString; // is set by the what function
};

2.2.8.2.2. Details

virtual std::string getName() const = 0
Returns:the name of the exception.
virtual const char *what() const noexcept
Returns:the description for the exception.
void printStacktrace(unsigned int frameLimit, std::ostream &s) const

Print the stacktrace captured when the exception was constructed. See Stacktrace::print().

2.2.8.3. Class FatalError

class FatalError : public Exception

When thrown there is no exception safety. It is not safe to continue after catching it.

2.2.8.3.1. Synopsis

struct FatalError : public Exception {
    FatalError(std::string &&text, unsigned int numSkip) : Exception(std::move(text), numSkip) { }
    FatalError(std::string &&text) : Exception(std::move(text)) { }
    std::string getName() const {
        return "MØD FatalError";
    }
    const char *what() const noexcept;
};

2.2.8.4. Class InputError

class InputError : public Exception

When thrown there is strong exception safety. This exception is thrown when bad data has been provided to a loading function.

2.2.8.4.1. Synopsis

struct InputError : public Exception {
    InputError(std::string &&text) : Exception(std::move(text)) { }
    std::string getName() const {
        return "MØD InputError";
    }
};

2.2.8.5. Class LogicError

class LogicError : public Exception

When thrown there is strong exception safety. This exception is thrown when a pre-condition of a function is violated.

2.2.8.5.1. Synopsis

struct LogicError : public Exception {
    LogicError(std::string &&text) : Exception(std::move(text)) { }
    std::string getName() const {
        return "MØD LogicError";
    }
};