My Project
Loading...
Searching...
No Matches
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 LOMIRI_EXCEPTION_H
20#define LOMIRI_EXCEPTION_H
21
22#include <lomiri/SymbolExport.h>
23
24#include <exception>
25#include <string>
26#include <memory>
27
28namespace lomiri
29{
30
31class ExceptionImplBase;
32
102
103class LOMIRI_API Exception : public std::exception, public std::nested_exception
104{
105public:
107 Exception(Exception const&);
108 Exception& operator=(Exception const&);
109 virtual ~Exception() noexcept;
111
112 char const* what() const noexcept override;
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
131protected:
132 Exception(std::string const& name, std::string const& reason);
133
134private:
135 std::string name_;
136 std::string reason_;
137 mutable std::string what_;
138 std::exception_ptr earlier_;
139};
140
141} // namespace lomiri
142
143#endif
char const * what() const noexcept override
Returns a string describing the exception, including any exceptions that were nested or chained.
Definition Exception.cpp:189
std::exception_ptr remember(std::exception_ptr earlier_exception)
Adds an exception to the exception history chain.
Definition Exception.cpp:307
Exception(std::string const &name, std::string const &reason)
Constructs an exception instance.
Definition Exception.cpp:165
std::string to_string(std::string const &indent=" ") const
Returns a string describing the exception, including any exceptions that were nested or chained.
Definition Exception.cpp:241
std::string reason() const
Returns the reason set by the derived class's constructor (empty string if none).
Definition Exception.cpp:224
std::string name() const
Returns the name set by the derived class's constructor.
Definition Exception.cpp:212
std::exception_ptr get_earlier() const noexcept
Returns the previous exception.
Definition Exception.cpp:323
virtual std::exception_ptr self() const =0
Returns a std::exception_ptr to this.
Top-level namespace for all things Lomiri-related.
Definition Version.h:38