LIBTHEMIS
except.h
[詳解]
1 /**********************************************************************//*
8  * (c) 2001-2018 oZ/acy. ALL RIGHTS RESERVED.
9  */
10 #ifndef INC_THEMIS_EXCEPT_H__
11 #define INC_THEMIS_EXCEPT_H__
12 
13 #include <string>
14 #include <iostream>
15 #include <exception>
16 
17 namespace themis
18 {
19 
20 /*--------------------------------------*/
23 class EmptyException : public std::exception
24 {
25 public:
26  EmptyException() noexcept {}
27  virtual ~EmptyException() noexcept {}
28 
33  const char* what() const noexcept override
34  {
35  static const char rstr[] = "themis::EmptyException";
36  return rstr;
37  }
38 };
39 
40 
41 
42 //-------------------------------------------
43 class Exception;
44 
45 std::ostream& operator<<(std::ostream& os, const Exception& ex);
46 
50 class Exception : public EmptyException
51 {
52  friend std::ostream&
53  themis::operator<<(std::ostream& os, const Exception& ex);
54 
55 protected:
56  std::string msg_;
57 
58 public:
62  Exception() noexcept {}
63 
67  Exception(const std::string& m) : msg_(m) {}
68 
76  Exception(const std::string& c, const std::string& f, const std::string& m)
77  {
78  msg_ = c + "::" + f + " : " + m;
79  }
80 
83 
88  const char* what() const noexcept override
89  {
90  static const char rstr[] = "themis::Exception";
91  return rstr;
92  }
93 };
94 
95 
99 inline std::ostream& operator<<(std::ostream& os, const Exception& ex)
100 {
101  return os << ex.msg_;
102 }
103 
104 
105 }// end of namespace themis
106 
107 
108 #endif
Definition: except.h:17
std::string msg_
メッセージ文字列
Definition: except.h:56
Exception(const std::string &m)
構築子
Definition: except.h:67
const char * what() const noexcept override
エラー内容取得
Definition: except.h:33
EmptyException() noexcept
Definition: except.h:26
~Exception()
解體子
Definition: except.h:82
Exception() noexcept
デフォルト構築子
Definition: except.h:62
メッセージ文字列を持つ例外クラス
Definition: except.h:50
const char * what() const noexcept override
エラー内容取得
Definition: except.h:88
空の例外クラス
Definition: except.h:23
Exception(const std::string &c, const std::string &f, const std::string &m)
メッセージ文字列の頭にクラス名、函數名を附加する場合の構築子
Definition: except.h:76
std::ostream & operator<<(std::ostream &os, const Exception &ex)
出力ストリームにメッセージ文字列を出力
Definition: except.h:99
virtual ~EmptyException() noexcept
Definition: except.h:27