PLCnext API Documentation 24.0.0.71
Exception.hpp
1
2//
3// Copyright PHOENIX CONTACT Electronics GmbH
4//
6#pragma once
8#include <memory>
9#include <iostream>
10
11namespace Arp
12{
13
16{
17public: // typedefs
19 typedef std::shared_ptr<Exception> Ptr;
20
21public: // construction/destruction (policies)
25 template<typename... Args>
26 Exception(const char* message, const Args& ... args);
29 Exception(const String& message);
32 Exception(String&& message);
36 Exception(const String& message, const Exception& innerException);
40 Exception(String&& message, Exception&& innerException);
43 Exception(const Exception& arg) = default;
46 Exception(Exception&& arg) = default;
48 virtual ~Exception(void) = default;
49
50protected: //construction
54 Exception(String&& message, const Exception::Ptr& innerExceptionPtr);
55
56public: // setter/getter properties
60 uint32 GetTypeCode(void)const;
63 const String& GetMessage(void)const;
66 bool HasInnerException(void)const;
70
71public: // operations
75 String ToString(void)const;
76
77protected: // operations to override
80 virtual Exception::Ptr Clone(void)const;
85 virtual String Format(int indentLevel, bool withInnerException)const;
89 virtual uint32 GetTypeCodeInternal(void)const;
90
91private: // deleted methods
92 Exception& operator=(const Exception& arg) = delete;
93
94private: // fields
95 String message;
96 Exception::Ptr innerExceptionPtr;
97
98protected: // static fields
99 const static int indentSize = 3;
100 const static int indentChar = ' ';
101 const static int innerIndentChar = '-';
102};
103
105// inline methods of class Exception
106template<typename... Args>
107inline Exception::Exception(const char* messageArg, const Args& ... args)
108 : message(String::Format(messageArg, args...))
109{
110}
111
112inline Exception::Exception(const String& messageArg)
113 : message(messageArg)
114{
115}
116
117inline Exception::Exception(String&& messageArg)
118 : message(std::move(messageArg))
119{
120}
121
122inline Exception::Exception(const String& messageArg, const Exception& innerException)
123 : message(messageArg), innerExceptionPtr(innerException.Clone())
124{
125}
126
127inline Exception::Exception(String&& messageArg, Exception&& innerException)
128 : message(std::move(messageArg)), innerExceptionPtr(innerException.Clone())
129{
130}
131
132inline Exception::Exception(String&& messageArg, const Exception::Ptr& innerException)
133 : message(std::move(messageArg)), innerExceptionPtr(innerException)
134{
135}
136
137inline const String& Exception::GetMessage()const
138{
139 return this->message;
140}
141
143{
144 return (bool)this->innerExceptionPtr;
145}
146
148{
149 return this->innerExceptionPtr;
150}
151
153{
154 return this->GetTypeCodeInternal();
155}
156
158// global operators of class Exception
159
164inline std::ostream& operator<<(std::ostream& os, const Exception& e)
165{
166 os << e.ToString();
167 return os;
168}
169
170} // end of namesapce Arp
This is the base class of all Arp exception classes.
Definition: Exception.hpp:16
Exception::Ptr GetInnerException(void) const
Gets the inner exception of this exception.
Definition: Exception.hpp:147
uint32 GetTypeCode(void) const
Gets the type code of this exception.
Definition: Exception.hpp:152
const String & GetMessage(void) const
Gets the error message of this exception.
Definition: Exception.hpp:137
std::shared_ptr< Exception > Ptr
The smart pointer tpye of this class.
Definition: Exception.hpp:19
virtual Exception::Ptr Clone(void) const
Clones this instance.
Exception(Exception &&arg)=default
Constructs an instance of class Exception.
String ToString(void) const
Gets a reasonable string representation of this exception.
static const int indentChar
The indentation character (blank)
Definition: Exception.hpp:100
virtual uint32 GetTypeCodeInternal(void) const
Get the type code of this exception. Must be overridden by derived classes.
bool HasInnerException(void) const
Determines if this exception has an inner exception.
Definition: Exception.hpp:142
static const int indentSize
The indentation size (count of blanks)
Definition: Exception.hpp:99
virtual String Format(int indentLevel, bool withInnerException) const
Formats this exception using the given indent level.
Exception(const Exception &arg)=default
Constructs an instance of class Exception.
Exception(const char *message, const Args &... args)
Constructs an instance of class Exception.
Definition: Exception.hpp:107
static const int innerIndentChar
The indentation character to indent inner exceptions.
Definition: Exception.hpp:101
virtual ~Exception(void)=default
Destructs this instance virually.
std::ostream & operator<<(std::ostream &os, const BasicString< CharType, Alloc > &right)
Streams the right string to the outstream os .
Definition: BasicString.hxx:1740
std::uint32_t uint32
The Arp unsigned integer type of 4 byte size.
Definition: PrimitiveTypes.hpp:36
Root namespace for the PLCnext API
Namespace of the C++ standard library