-
-
Notifications
You must be signed in to change notification settings - Fork 43
/
Copy pathException.h
83 lines (75 loc) · 2.7 KB
/
Exception.h
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
//==============================================================================
//
// Exception.h
//
// Copyright (C) 2013-2022 Greg Utas
//
// This file is part of the Robust Services Core (RSC).
//
// RSC is free software: you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the Free Software
// Foundation, either version 3 of the License, or (at your option) any later
// version.
//
// RSC 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 General Public License for more
// details.
//
// You should have received a copy of the GNU General Public License along
// with RSC. If not, see <http://www.gnu.org/licenses/>.
//
#ifndef EXCEPTION_H_INCLUDED
#define EXCEPTION_H_INCLUDED
#include <exception>
#include <iosfwd>
#include <sstream>
#include <string>
#include "SysTypes.h"
//------------------------------------------------------------------------------
namespace NodeBase
{
// All exceptions should be subclassed from this. It is virtual and cannot
// be thrown itself, but it ensures that all subclasses capture the function
// call stack for debugging purposes.
//
class Exception : public std::exception
{
public:
// Deleted to prohibit assignment.
//
Exception& operator=(const Exception& that) = delete;
Exception& operator=(const Exception&& that) = delete;
// Outputs information about the exception in STREAM. INDENT specifies
// how far to indent the output. The implementation provided here does
// nothing because the call stack is output separately.
//
virtual void Display(std::ostream& stream, const std::string& prefix) const;
// Returns the stream that contains the call stack.
//
std::ostringstream* Stack() const { return stack_.get(); }
protected:
// Captures the call stack in stack_ if STACK is true. Protected because
// this class is virtual.
//
explicit Exception(bool stack);
// Exceptions need to be copyable, so transfer ownership of stack_.
//
Exception(const Exception& that);
Exception(Exception&& that);
// Protected to restrict deletion. Virtual to allow subclassing.
//
virtual ~Exception();
// Overridden so that Thread::Start can catch this exception. Subclasses
// should override this implementation.
//
const char* what() const noexcept override;
private:
// The function call stack at the time that the exception occurred.
// Mutable so that the copy constructor can transfer ownership if
// an exception is caught and rethrown.
//
mutable ostringstreamPtr stack_;
};
}
#endif