mpw-shell/error.h
Kelvin Sherlock f125b533f7 Squashed commit of the following:
commit f0944a89f27e44b1764988806e655f09764e80df
Author: Kelvin Sherlock <ksherlock@gmail.com>
Date:   Tue Aug 30 12:24:08 2016 -0400

    exit throws execution of input error w/ possible 0 value.  catch it.

commit 9e7f9c1ae049aa26513413f4767268b47ee22e98
Author: Kelvin Sherlock <ksherlock@gmail.com>
Date:   Tue Aug 30 12:23:21 2016 -0400

    builtins - more consistent argument handling.

commit be4c1c902f5a3a3f01e92ae52c7d6cc5d8731b65
Author: Kelvin Sherlock <ksherlock@gmail.com>
Date:   Tue Aug 30 12:23:01 2016 -0400

    .

commit 68d0c29fec112c6e7bc3a672b41eb7eb758a8941
Author: Kelvin Sherlock <ksherlock@gmail.com>
Date:   Tue Aug 30 12:22:51 2016 -0400

    exit command.

commit 25b0a7f7da9220b03026123bb5072c2da1d73fde
Author: Kelvin Sherlock <ksherlock@gmail.com>
Date:   Tue Aug 30 12:21:16 2016 -0400

    builtin quit command.
2016-08-30 12:25:43 -04:00

81 lines
1.7 KiB
C++

#ifndef __mpw_error_h__
#define __mpw_error_h__
#include <stdexcept>
#include <system_error>
class mpw_error : public std::runtime_error {
public:
mpw_error(int status, const std::string &s) : std::runtime_error(s), _status(status)
{}
mpw_error(int status, const char *s) : std::runtime_error(s), _status(status)
{}
int status() const noexcept { return _status; }
private:
int _status;
};
class execution_of_input_terminated : public mpw_error {
public:
execution_of_input_terminated(int status = -9) :
mpw_error(status, "MPW Shell - Execution of input Terminated.")
{}
};
class break_error : public mpw_error {
public:
break_error(int status = -3) :
mpw_error(status, "MPW Shell - Break must be within for or loop.")
{}
};
class continue_error : public mpw_error {
public:
continue_error(int status = -3) :
mpw_error(status, "MPW Shell - Continue must be within for or loop.")
{}
};
class estring_error: public mpw_error {
public:
estring_error(int status = -3) :
mpw_error(status, "MPW Shell - `s must occur in pairs.")
{}
};
class vstring_error: public mpw_error {
public:
vstring_error(int status = -3) :
mpw_error(status, "MPW Shell - {s must occur in pairs.")
{}
};
class sstring_error: public mpw_error {
public:
sstring_error(int status = -3) :
mpw_error(status, "MPW Shell - 's must occur in pairs.")
{}
};
class dstring_error: public mpw_error {
public:
dstring_error(int status = -3) :
mpw_error(status, "MPW Shell - \"s must occur in pairs.")
{}
};
/*
these are used for flow-control.
they do not inherit from std::exception to prevent being caught
by normal handlers.
*/
struct break_command_t {};
struct continue_command_t {};
struct exit_command_t { int value = 0; };
struct quit_command_t {};
#endif