树  0.1
数据结构_第6章
TreeException.hh
Go to the documentation of this file.
1 /****************************************************
2  * @file TreeException.hh
3  * @author Guorui Wei (313017602@qq.com)
4  * @brief 树的异常类
5  * @version 0.1
6  * @date 2020-04-19
7  *
8  * @copyright Copyright (c) 2020
9  *
10  * See the file LICENSE in the top directory of this distribution for
11  * more information.
12  *
13  ****************************************************/
14 
15 #ifndef INCLUDE_TREEEXCEPTION_HH_
16 #define INCLUDE_TREEEXCEPTION_HH_
17 
18 #include <exception>
19 #include <string>
20 
21 namespace Tree
22 {
23 
28 class TreeException : public std::exception
29 {
30 public:
38  TreeException(const std::string &text = "undefined exception",
39  const std::string &id = "undefined",
40  const std::string &td = "Generic ArgException")
41  : std::exception(),
42  _errorText(text),
43  _argId(id),
44  _typeDescription(td) {}
45 
49  virtual ~TreeException() noexcept {}
50 
54  std::string error() const { return (_errorText); }
55 
59  std::string argId() const
60  {
61  if (_argId == "undefined")
62  return " ";
63  else
64  return ("Argument: " + _argId);
65  }
66 
70  const char *what() const noexcept
71  {
72  static std::string ex;
73  ex = _argId + " -- " + _errorText;
74  return ex.c_str();
75  }
76 
81  std::string typeDescription() const { return _typeDescription; }
82 
83 private:
87  std::string _errorText;
88 
92  std::string _argId;
93 
98  std::string _typeDescription;
99 };
100 } // namespace Tree
101 
102 #endif /* INCLUDE_TREEEXCEPTION_HH_ */
Tree::TreeException::_argId
std::string _argId
Definition: TreeException.hh:116
Tree::TreeException::_errorText
std::string _errorText
Definition: TreeException.hh:111
Tree::TreeException::typeDescription
std::string typeDescription() const
Definition: TreeException.hh:105
Tree::TreeException::argId
std::string argId() const
Definition: TreeException.hh:83
Tree
自定义的树类都在Tree名字空间内
Definition: binaryTree.hh:27
Tree::TreeException::TreeException
TreeException(const std::string &text="undefined exception", const std::string &id="undefined", const std::string &td="Generic ArgException")
Definition: TreeException.hh:62
Tree::TreeException::error
std::string error() const
Definition: TreeException.hh:78
Tree::TreeException::~TreeException
virtual ~TreeException() noexcept
Definition: TreeException.hh:73
Tree::TreeException::_typeDescription
std::string _typeDescription
Definition: TreeException.hh:122
Tree::TreeException::what
const char * what() const noexcept
Definition: TreeException.hh:94