Option++  2.0
C++ library for reading command-line options
error.hpp
Go to the documentation of this file.
1 /* Option++ -- read command-line program options
2  * Copyright (C) 2017-2020 Greg Kikola.
3  *
4  * This file is part of Option++.
5  *
6  * Option++ is free software: you can redistribute it and/or modify
7  * it under the terms of the Boost Software License version 1.0.
8  *
9  * Option++ is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * Boost Software License for more details.
13  *
14  * You should have received a copy of the Boost Software License
15  * along with Option++. If not, see
16  * <https://www.boost.org/LICENSE_1_0.txt>.
17  */
18 /* Written by Greg Kikola <[email protected]>. */
19 
25 #ifndef OPTIONPP_ERROR_HPP
26 #define OPTIONPP_ERROR_HPP
27 
28 #include <stdexcept>
29 #include <string>
30 
31 namespace optionpp {
32 
36  class error : public std::logic_error {
37  public:
43  error(const std::string& msg, const std::string& fn_name)
44  : logic_error(msg), m_function{fn_name} {}
45 
50  const std::string& function() const { return m_function; }
51 
52  private:
53  std::string m_function; //< Function in which error occurred.
54  };
55 
59  class out_of_range : public error {
60  public:
66  out_of_range(const std::string& msg, const std::string& fn_name)
67  : error(msg, fn_name) {}
68  };
69 
73  class bad_dereference : public error {
74  public:
80  bad_dereference(const std::string& msg,
81  const std::string& fn_name)
82  : error(msg, fn_name) {}
83  };
84 
88  class type_error : public error {
89  public:
95  type_error(const std::string& msg, const std::string& fn_name)
96  : error(msg, fn_name) {}
97  };
98 
99 } // End namespace
100 
101 #endif
optionpp::out_of_range
Exception indicating out of range access.
Definition: error.hpp:59
optionpp::error::error
error(const std::string &msg, const std::string &fn_name)
Constructor.
Definition: error.hpp:43
optionpp::bad_dereference::bad_dereference
bad_dereference(const std::string &msg, const std::string &fn_name)
Constructor.
Definition: error.hpp:80
optionpp::bad_dereference
Exception indicating an invalid iterator was dereferenced.
Definition: error.hpp:73
optionpp::type_error::type_error
type_error(const std::string &msg, const std::string &fn_name)
Constructor.
Definition: error.hpp:95
optionpp::out_of_range::out_of_range
out_of_range(const std::string &msg, const std::string &fn_name)
Constructor.
Definition: error.hpp:66
optionpp
Library namespace.
Definition: error.hpp:31
optionpp::type_error
Exception indicating a type error.
Definition: error.hpp:88
optionpp::error
Base class for library exceptions.
Definition: error.hpp:36