My Project
Exception.h
1 /*
2  * Copyright (C) 2013 Canonical Ltd
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License version 3 as
6  * published by the Free Software Foundation.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU Lesser General Public License for more details.
12  *
13  * You should have received a copy of the GNU Lesser General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  *
16  * Authored by: Michi Henning <michi.henning@canonical.com>
17  */
18 
19 #ifndef UNITY_EXCEPTION_H
20 #define UNITY_EXCEPTION_H
21 
22 #include <unity/SymbolExport.h>
23 
24 #include <exception>
25 #include <string>
26 #include <memory>
27 
28 namespace unity
29 {
30 
31 class ExceptionImplBase;
32 
103 class UNITY_API Exception : public std::exception, public std::nested_exception
104 {
105 public:
107  Exception(Exception const&);
108  Exception& operator=(Exception const&);
109  virtual ~Exception() noexcept;
111 
112  virtual char const* what() const noexcept;
113 
120  virtual std::exception_ptr self() const = 0;
121 
122  std::string name() const;
123  std::string reason() const;
124 
125  std::string to_string(std::string const& indent = " ") const;
126  std::string to_string(int indent_level, std::string const& indent) const;
127 
128  std::exception_ptr remember(std::exception_ptr earlier_exception);
129  std::exception_ptr get_earlier() const noexcept;
130 
131 protected:
132  Exception(std::string const& name, std::string const& reason);
133 
134 private:
135  std::string name_;
136  std::string reason_;
137  mutable std::string what_;
138  std::exception_ptr earlier_;
139 };
140 
141 } // namespace unity
142 
143 #endif
Abstract base class for all Unity exceptions.
Definition: Exception.h:103
Top-level namespace for all things Unity-related.
Definition: Version.h:37