PLCnext API Documentation 25.0.2.69
ArgumentException.hpp
1
2//
3// Copyright Phoenix Contact GmbH & Co. KG
4//
6#pragma once
7#ifndef ARP_USE_ARP_SYSTEM_COMMONS_EXCEPTIONS
8#include "Arp/Base/Commons/Exceptions/ArgumentException.hpp"
9namespace Arp
10{
12}
13#else
14#include "Arp/System/Core/Arp.h"
15#include "Arp/System/Commons/Exceptions/CommonException.hpp"
16
17namespace Arp { namespace System { namespace Commons
18{
19
21class ArgumentException : public CommonException
22{
23public: // construction/destruction
24 template<typename... Args>
25 ArgumentException(const char* message, const Args& ... args);
26 ArgumentException(const String& message);
27 ArgumentException(String&& message);
28 ArgumentException(const String& message, const Exception& innerException);
29 ArgumentException(String&& message, Exception&& innerException);
30 ArgumentException(const ArgumentException& arg) = default;
31 ArgumentException(ArgumentException&& arg) = default;
32 virtual ~ArgumentException(void) = default;
33
34protected: // construction
35 ArgumentException(ExceptionTypeId typeId, String&& message, int skipStackTraceDepth = 3);
36 ArgumentException(ExceptionTypeId typeId, const String& message, int skipStackTraceDepth = 3);
37 ArgumentException(ExceptionTypeId typeId, String&& message, Exception&& innerException, int skipStackTraceDepth = 3);
38 ArgumentException(ExceptionTypeId typeId, const String& message, const Exception& innerException, int skipStackTraceDepth = 3);
39
40public: // static factory methods
41 template<class T>
42 static ArgumentException Create(const char* paramName, const T& paramValue);
43 template<class T>
44 static ArgumentException Create(const char* paramName, const T& paramValue, const Exception& innerException);
45 template<class T>
46 static ArgumentException Create(const char* paramName, const T& paramValue, const char* message);
47
48protected: // overridden operations
49 Exception::Ptr Clone(void)const override;
50
51private: // deleted methods
52 ArgumentException& operator=(const ArgumentException& arg) = delete;
53
54private:
55 static const char* const defaultMessage;
56 static const char* const defaultMessage2;
57};
58
60// inline methods of class ArgumentException
61
63template<typename... Args>
64inline ArgumentException::ArgumentException(const char* message, const Args& ... args)
65 : CommonException(ExceptionTypeId::Argument, String::Format(message, args...))
66{
67}
68
70inline ArgumentException::ArgumentException(const String& message)
71 : CommonException(ExceptionTypeId::Argument, message)
72{
73}
74
76inline ArgumentException::ArgumentException(String&& message)
77 : CommonException(ExceptionTypeId::Argument, std::move(message))
78{
79}
80
82inline ArgumentException::ArgumentException(const String& message, const Exception& innerException)
83 : CommonException(ExceptionTypeId::Argument, message, innerException)
84{
85}
86
88inline ArgumentException::ArgumentException(String&& message, Exception&& innerException)
89 : CommonException(ExceptionTypeId::Argument, std::move(message), std::move(innerException))
90{
91}
92
94inline ArgumentException::ArgumentException(ExceptionTypeId typeId, const String& message, int skipStackTraceDepth)
95 : CommonException(typeId, message, skipStackTraceDepth)
96{
97}
98
100inline ArgumentException::ArgumentException(ExceptionTypeId typeId, String&& message, int skipStackTraceDepth)
101 : CommonException(typeId, std::move(message), skipStackTraceDepth)
102{
103}
104
106inline ArgumentException::ArgumentException(ExceptionTypeId typeId, const String& message, const Exception& innerException, int skipStackTraceDepth)
107 : CommonException(typeId, message, innerException, skipStackTraceDepth)
108{
109}
110
112inline ArgumentException::ArgumentException(ExceptionTypeId typeId, String&& message, Exception&& innerException, int skipStackTraceDepth)
113 : CommonException(typeId, std::move(message), std::move(innerException), skipStackTraceDepth)
114{
115}
116
118template<class T>
119inline ArgumentException ArgumentException::Create(const char* paramName, const T& paramValue)
120{
121 return ArgumentException(defaultMessage, paramName, paramValue);
122}
123
125template<class T>
126ArgumentException ArgumentException::Create(const char* paramName, const T& paramValue, const Exception& innerException)
127{
128 return ArgumentException(String::Format(defaultMessage, paramName, paramValue), innerException);
129}
130
132template<class T>
133ArgumentException ArgumentException::Create(const char* paramName, const T& paramValue, const char* message)
134{
135 return ArgumentException(String::Format(defaultMessage2, paramName, paramValue, message));
136}
137
138}}} // end of namesapce Arp::System::Commons
139
141// template specialization of ArgumentException formatter
142template<> struct fmt::formatter<Arp::System::Commons::ArgumentException> : public fmt::ostream_formatter {};
143
144#endif // ndef ARP_USE_ARP_SYSTEM_COMMONS_EXCEPTIONS
This exception is thrown when an invalid argument occurs.
Definition: ArgumentException.hpp:17
ArgumentException(const ArgumentException &arg)
Default copy constructor.
std::unique_ptr< Exception > Ptr
The smart pointer type of this class.
Definition: Exception.hpp:27
@ Create
Creates a new file. If the file already exists, it is overwritten.
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