/usr/include/unity/Exception.h is in libunity-api-dev 7.108+16.04.20160322-0ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 | /*
* 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;
/**
\brief Abstract base class for all Unity exceptions.
This class is the base class for all Unity exceptions. Besides providing a common base class for
structured exception handling, this class provides features to capture nested exceptions (for
exceptions that are re-thrown) and to chain exceptions into an exception history that allows
a number of exceptions to be remembered before throwing a new exception.
The exception nesting is provided by the derivation from <code>std::nested_exception</code>. If you
catch an exception and throw another exception from the catch handler, the caught exception
is automatically preserved; you can access nested exceptions by calling the <code>nested_ptr()</code> and
<code>rethrow_nested()</code> member functions of <code>std::nested_exception</code>.
In addition, you can remember one or more exceptions by calling remember(). This is useful in situations
where you need to perform a number of actions that may fail with an error code, and you do not want to
throw an exception until all of the actions have been attempted. This is particularly useful in shutdown
scenarios, where it is often impossible to recover from an error, but it is still desirable to try to
shut down as much as possible before reporting or logging the errors:
~~~
void
shutdown()
{
using namespace std;
exception_ptr ep;
try
{
shutdown_action_1();
}
catch (SomeException const&)
{
ep = make_exception_ptr(current_exception());
}
try
{
shutdown_action_2();
}
catch (SomeOtherException const&)
{
ep = e.remember(ep);
}
int err = shutdown_action_3();
if (err != 0)
{
try
{
throw YetAnotherException(err);
}
catch (YetAnotherException const& e)
{
ep = e.remember(ep);
}
}
if (ep)
{
rethrow_exception(ep);
}
}
~~~
Calling what() on a caught exception returns a string with the entire exception history (both nested and
chained).
*/
class UNITY_API Exception : public std::exception, public std::nested_exception
{
public:
//! @cond
Exception(Exception const&);
Exception& operator=(Exception const&);
virtual ~Exception() noexcept;
//! @endcond
virtual char const* what() const noexcept;
/**
\brief Returns a <code>std::exception_ptr</code> to <code>this</code>.
\note Derived exceptions must implement this member function so the implemention of remember()
(provided by this abstract base class) can return a <code>std::exception_ptr</code> to its own derived exception.
*/
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
|