Loading...
Searching...
No Matches
Exception.h
/*
* Copyright (C) 2013 Canonical Ltd
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version 3 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Authored by: Michi Henning <michi.henning@canonical.com>
*/
#ifndef UNITY_EXCEPTION_H
#define UNITY_EXCEPTION_H
#include <unity/SymbolExport.h>
#include <exception>
#include <string>
#include <memory>
namespace unity
{
class ExceptionImplBase;
class UNITY_API Exception : public std::exception, public std::nested_exception
{
public:
Exception(Exception const&);
Exception& operator=(Exception const&);
virtual ~Exception() noexcept;
char const* what() const noexcept override;
virtual std::exception_ptr self() const = 0;
std::string name() const;
std::string reason() const;
std::string to_string(std::string const& indent = " ") const;
std::string to_string(int indent_level, std::string const& indent) const;
std::exception_ptr remember(std::exception_ptr earlier_exception);
std::exception_ptr get_earlier() const noexcept;
protected:
Exception(std::string const& name, std::string const& reason);
private:
std::string name_;
std::string reason_;
mutable std::string what_;
std::exception_ptr earlier_;
};
} // namespace unity
#endif
unity::Exception::remember
std::exception_ptr remember(std::exception_ptr earlier_exception)
Adds an exception to the exception history chain.
Definition Exception.cpp:307
unity::Exception::to_string
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
unity::Exception::get_earlier
std::exception_ptr get_earlier() const noexcept
Returns the previous exception.
Definition Exception.cpp:323
unity::Exception::what
char const * what() const noexcept override
Returns a string describing the exception, including any exceptions that were nested or chained.
Definition Exception.cpp:189
unity::Exception::Exception
Exception(std::string const &name, std::string const &reason)
Constructs an exception instance.
Definition Exception.cpp:165
unity::Exception::reason
std::string reason() const
Returns the reason set by the derived class's constructor (empty string if none).
Definition Exception.cpp:224
unity::Exception::name
std::string name() const
Returns the name set by the derived class's constructor.
Definition Exception.cpp:212
unity::Exception::self
virtual std::exception_ptr self() const =0
Returns a std::exception_ptr to this.
unity
Top-level namespace for all things Unity-related.
Definition Version.h:38