PLCnext API Documentation  22.9.0.33
CommonException.hpp
1 //
3 // Copyright PHOENIX CONTACT Electronics GmbH
4 //
6 #pragma once
7 #include "Arp/System/Core/Arp.h"
8 #include "Arp/System/Core/Exception.hpp"
9 #include "Arp/System/Commons/Exceptions/ExceptionTypeId.hpp"
10 #include "Arp/System/Commons/Runtime/StackTrace.hpp"
11 
12 namespace Arp { namespace System { namespace Commons
13 {
14 
15 using namespace Arp::System::Commons::Runtime;
16 
18 class CommonException : public Exception
19 {
20 protected: // construction/destruction
21  CommonException(ExceptionTypeId typeId, const String& message, int skipStackTraceDepth = 0);
22  CommonException(ExceptionTypeId typeId, String&& message, int skipStackTraceDepth = 0);
23  CommonException(ExceptionTypeId typeId, const String& message, const Exception& innerException, int skipStackTraceDepth = 0);
24  CommonException(ExceptionTypeId typeId, String&& message, Exception&& innerException, int skipStackTraceDepth = 0);
25  CommonException(ExceptionTypeId typeId, String&& message, Exception::Ptr&& innerExceptionPtr, int skipStackTraceDepth = 0);
26  CommonException(const CommonException& arg) = default;
27  CommonException(CommonException&& arg) = default;
28  virtual ~CommonException(void) = default;
29 
30 public: // getter
31  ExceptionTypeId GetTypeId(void)const;
32 
33 protected: // overridden operations
34  String Format(int indentLevel, bool withInnerException)const override;
35  uint32 GetTypeCodeInternal(void)const override;
36 
37 private: // deleted methods
38  CommonException& operator=(const CommonException& arg) = delete;
39 
40 private: // fields
41  StackTrace stackTrace;
42  ExceptionTypeId typeId;
43 };
44 
46 // inline methods of class Exception
48 inline CommonException::CommonException(ExceptionTypeId typeIdArg, const String& messageArg, int skipStackTraceDepth)
49  : Exception(messageArg)
50  , stackTrace(std::move(StackTrace::GetCurrent(skipStackTraceDepth)))
51  , typeId(typeIdArg)
52 {
53 }
54 
56 inline CommonException::CommonException(ExceptionTypeId typeIdArg, String&& messageArg, int skipStackTraceDepth)
57  : Exception(std::move(messageArg))
58  , stackTrace(std::move(StackTrace::GetCurrent(skipStackTraceDepth)))
59  , typeId(typeIdArg)
60 {
61 }
62 
64 inline CommonException::CommonException(ExceptionTypeId typeIdArg, const String& messageArg, const Exception& innerException, int skipStackTraceDepth)
65  : Exception(messageArg, innerException)
66  , stackTrace(std::move(StackTrace::GetCurrent(skipStackTraceDepth)))
67  , typeId(typeIdArg)
68 {
69 }
70 
72 inline CommonException::CommonException(ExceptionTypeId typeIdArg, String&& messageArg, Exception&& innerException, int skipStackTraceDepth)
73  : Exception(std::move(messageArg), std::move(innerException))
74  , stackTrace(std::move(StackTrace::GetCurrent(skipStackTraceDepth)))
75  , typeId(typeIdArg)
76 {
77 }
78 
80 inline CommonException::CommonException(ExceptionTypeId typeIdArg, String&& messageArg, Exception::Ptr&& innerExceptionPtrArg, int skipStackTraceDepth)
81  : Exception(std::move(messageArg), std::move(innerExceptionPtrArg))
82  , stackTrace(std::move(StackTrace::GetCurrent(skipStackTraceDepth)))
83  , typeId(typeIdArg)
84 {
85 }
86 
90 {
91  return this->typeId;
92 }
93 
94 }}} // end of namesapce Arp::System::Commons
This is the base class of all Arp exception classes.
Definition: Exception.hpp:16
std::shared_ptr< Exception > Ptr
The smart pointer tpye of this class.
Definition: Exception.hpp:19
This is the base class of common exception classes.
Definition: CommonException.hpp:19
ExceptionTypeId GetTypeId(void) const
Returns the ExceptionTypeId of this exception.
Definition: CommonException.hpp:89
CommonException(ExceptionTypeId typeId, const String &message, int skipStackTraceDepth=0)
Constructs an CommonException instance.
Definition: CommonException.hpp:48
String Format(int indentLevel, bool withInnerException) const override
Formats this exception using the given indent level.
uint32 GetTypeCodeInternal(void) const override
Get the type code of this exception. Must be overridden by derived classes.
Definition: StackTrace.hpp:14
std::uint32_t uint32
The Arp unsigned integer type of 4 byte size.
Definition: PrimitiveTypes.hpp:35
@ System
System components used by the System, Device, Plc or Io domains.
Namespace for high level API for controlling processes, shared libraries, etc.
Definition: SharedLibrary.hpp:16
ExceptionTypeId
Specifies the type id of any exception derived by <see cref="CommonException".
Definition: ExceptionTypeId.hpp:15
Root namespace for the PLCnext API
Namespace of the C++ standard library