PLCnext API Documentation 25.0.2.69
Exception.hpp
1
2//
3// Copyright Phoenix Contact GmbH & Co. KG
4//
6#pragma once
9#include "Arp/Base/Core/ExceptionTypeId.hpp"
10#include <memory>
11
12namespace Arp { namespace Base { namespace Core
13{
14
20class ARP_BASE_CORE_EXPORT Exception
21{
22public: // Impl forward declaration
23 class Impl;
24
25public: // usings
27 using Ptr = std::unique_ptr<Exception>;
29 using TypeCode = std::underlying_type<Arp::Base::Core::ExceptionTypeId>::type;
30
31public: // canonical construction/destruction/assignment
32 Exception(const Exception& arg);
33 Exception(Exception&& arg)noexcept;
35 Exception& operator=(Exception&& arg)noexcept;
36 virtual ~Exception(void);
37
38public: // construction
39 Exception(void);
40 template<typename... Args>
41 Exception(const char* message, Args&& ... args);
42 explicit Exception(const String& message);
43 explicit Exception(String&& message);
44 Exception(const String& message, const Exception& innerException);
45 Exception(String&& message, const Exception& innerException);
46
47protected: //construction
48 Exception(ExceptionTypeId typeId, String&& message);
49 Exception(ExceptionTypeId typeId, const String& message);
50 Exception(ExceptionTypeId typeId, String&& message, const Exception& innerException);
51 Exception(ExceptionTypeId typeId, const String& message, const Exception& innerException);
52
53public: // setter operations
54 const String& GetMessage(void)const;
55 ExceptionTypeId GetTypeId(void)const;
56 TypeCode GetTypeCode(void)const;
57 bool HasInnerException(void)const;
58 const Exception& GetInnerException(void)const;
59
60public: // operations
61 String ToString(void)const;
62
63public: // operations to override
64 virtual Exception::Ptr Clone(void)const;
65 virtual String Format(bool withInnerException)const;
66
67public: // global (friend) operators
68 friend ARP_EXPORT std::ostream& operator<<(std::ostream& os, const Exception& arg);
69
70protected: // deprecated operations
71 ARP_DEPRECATED("Use the protected constructor 'Exception(ExceptionTypeId, String&&, const Exception&)' instead.")
72 Exception(String&& message, const Exception::Ptr& innerExceptionPtr);
73
74 ARP_DEPRECATED("Override 'Exception::Format(bool withInnerException)const' instead.")
75 String Format(int indentLevel, bool withInnerException)const;
76
77 ARP_DEPRECATED("Remove the override of this operation, it's not required any more.")
78 virtual uint32 GetTypeCodeInternal(void)const;
79
80public: // internal operations
81 Impl& GetImpl(void);
82 const Impl& GetImpl(void)const;
83
84private: // Impl usings
85 using Pimpl = PimplPtr<Impl, true>;
86
87private: // Impl fields
88 Pimpl pimpl;
89};
90
92// Declarations of global functions of class Exception
93ARP_EXPORT std::ostream& operator<<(std::ostream& os, const Exception& arg);
94
96// inline operations of class Exception
97
101template<typename... Args>
102inline Exception::Exception(const char* message, Args&& ... args)
103 : Exception(ExceptionTypeId::Exception, String::Format(message, std::forward<Args>(args)...))
104{
105}
106
107}}} // end of namespace Arp::Base::Core
108
109namespace Arp {
112}
114template<> struct fmt::formatter<Arp::Base::Core::Exception> : public fmt::ostream_formatter {};
This is the base class of all Arp exception classes.
Definition: Exception.hpp:21
Exception(Exception &&arg) noexcept
Default move constructor.
std::unique_ptr< Exception > Ptr
The smart pointer type of this class.
Definition: Exception.hpp:27
Exception(const Exception &arg)
Default copy constructor.
virtual ~Exception(void)
Default destructor.
Exception & operator=(Exception &&arg) noexcept
Default move-assignment operator.
std::underlying_type< Arp::Base::Core::ExceptionTypeId >::type TypeCode
The integral type of the type code.
Definition: Exception.hpp:29
Exception & operator=(const Exception &arg)
Default copy-assignment operator.
This class represents the Arp String. The implementation is based on std::string.
Definition: String.hpp:39
std::uint32_t uint32
The Arp unsigned integer type of 4 byte size.
Definition: PrimitiveTypes.hpp:33
Root namespace for the PLCnext API
class ARP_DEPRECATED("Use Arp::Enum<T> instead.") EnumStrings
Deprecated! The class implements an adapter for enums to define the string literals of the enum entri...
Definition: EnumStrings.hxx:38
Namespace of the C++ standard library