Calculator  Step 5
calc_error.hpp
Go to the documentation of this file.
1 #ifndef CALC_ERROR_HPP_
2 #define CALC_ERROR_HPP_
3 
4 #include <cerrno>
5 #include <cstdlib>
6 #include <cstring>
7 #include <stdexcept>
8 #include <string>
9 
11 class calc_error : public std::runtime_error
12 {
13 public:
14  calc_error(std::string const& msg) : runtime_error{msg} {}
15 };
16 
18 class parse_error : public calc_error {
19 public:
20  parse_error(std::string const& msg) : calc_error{msg} {}
21 };
22 
24 class syntax_error : public parse_error {
25 public:
26  syntax_error(std::string const& msg) : parse_error{"syntax error: " + msg} {}
27 };
28 
31 class function_error : public calc_error
32 {
33 public:
34  function_error(std::string const &name, std::size_t expected, std::size_t actual)
35  : calc_error{msg(name, expected, actual)}
36  {}
37 private:
38  std::string msg(std::string const& name, std::size_t expected, std::size_t actual);
39 };
40 
42 class no_such_function : public calc_error {
43 public:
44  no_such_function(std::string const& what) : calc_error{"unknown function: " + what} {}
45 };
46 
50 class file_error : public calc_error {
51 public:
52  file_error(std::string const& filename) : calc_error{filename + ": " + std::strerror(errno)} {}
53 };
54 
55 #endif
no_such_function(std::string const &what)
Definition: calc_error.hpp:44
parse_error(std::string const &msg)
Definition: calc_error.hpp:20
function_error(std::string const &name, std::size_t expected, std::size_t actual)
Definition: calc_error.hpp:34
calc_error(std::string const &msg)
Definition: calc_error.hpp:14
file_error(std::string const &filename)
Definition: calc_error.hpp:52
syntax_error(std::string const &msg)
Definition: calc_error.hpp:26
std::string msg(std::string const &name, std::size_t expected, std::size_t actual)
Definition: calc_error.cpp:5