fxos/shell/errors.h

43 lines
992 B
C++

//---
// fxos-shell.errors: Exceptions with particular handling
//---
#ifndef FXOS_ERRORS_H
#define FXOS_ERRORS_H
#include <fxos/errors.h>
#include <fmt/core.h>
#include <string>
/* Generic command error, either parsing or execution, which prevents a command
from accomplishing its intended task. */
class CommandError: public std::exception
{
public:
CommandError(std::string what): m_what(what) {}
/* Build directly from format arguments */
template <typename... Args>
CommandError(std::string const &format_str, Args&&... args):
m_what(fmt::format(format_str, args...)) {}
char const *what() const noexcept override {
return m_what.c_str();
}
private:
std::string m_what;
};
/* Command error when no virtual space is selected */
class NoVirtualSpaceError: public CommandError
{
public:
NoVirtualSpaceError():
CommandError("no virtual space") {}
NoVirtualSpaceError(std::string name):
CommandError("no virtual space '{}'", name) {}
};
#endif /* FXOS_ERRORS_H */