00001 #ifndef FUNCTON_ERROR_HPP_ 00002 #define FUNCTON_ERROR_HPP_ 00003 00004 #include <cstdlib> 00005 #include <stdexcept> 00006 #include <string> 00007 00014 class calc_error : public std::runtime_error 00015 { 00016 public: 00017 calc_error(std::string const& msg) : runtime_error(msg) {} 00018 }; 00019 00021 class parse_error : public calc_error { 00022 public: 00023 parse_error(std::string const& msg) : calc_error(msg) {} 00024 }; 00025 00027 class syntax_error : public parse_error { 00028 public: 00029 syntax_error(std::string const& msg) : parse_error("syntax error: " + msg) {} 00030 }; 00031 00034 class function_error : public calc_error 00035 { 00036 public: 00037 function_error(std::string const &name, std::size_t expected, std::size_t actual) 00038 : calc_error(msg(name, expected, actual)) 00039 {} 00040 private: 00041 std::string msg(std::string const& name, std::size_t expected, std::size_t actual); 00042 }; 00043 00045 class no_such_function : public calc_error { 00046 public: 00047 no_such_function(std::string const& what) : calc_error("unknown function: " + what) {} 00048 }; 00049 00050 #endif