PLCnext API Documentation  21.0.0.35466
ArgumentException.hpp
1 //
3 // Copyright PHOENIX CONTACT Electronics GmbH
4 //
6 #pragma once
7 #include "Arp/System/Core/Arp.h"
8 #include "Arp/System/Commons/Exceptions/CommonException.hpp"
9 
10 namespace Arp { namespace System { namespace Commons
11 {
12 
15 {
16 public: // construction/destruction
17  template<typename... Args>
18  ArgumentException(const char* message, const Args& ... args);
19  ArgumentException(const String& message);
20  ArgumentException(String&& message);
21  ArgumentException(const String& message, const Exception& innerException);
22  ArgumentException(String&& message, Exception&& innerException);
23  ArgumentException(const ArgumentException& arg) = default;
24  ArgumentException(ArgumentException&& arg) = default;
25  virtual ~ArgumentException(void) = default;
26 
27 protected: // construction
28  ArgumentException(ExceptionTypeId typeId, String&& message, int skipStackTraceDepth = 3);
29  ArgumentException(ExceptionTypeId typeId, const String& message, int skipStackTraceDepth = 3);
30  ArgumentException(ExceptionTypeId typeId, String&& message, Exception&& innerException, int skipStackTraceDepth = 3);
31  ArgumentException(ExceptionTypeId typeId, const String& message, const Exception& innerException, int skipStackTraceDepth = 3);
32 
33 public: // static factory methods
34  template<class T>
35  static ArgumentException Create(const char* paramName, const T& paramValue);
36  template<class T>
37  static ArgumentException Create(const char* paramName, const T& paramValue, const Exception& innerException);
38  template<class T>
39  static ArgumentException Create(const char* paramName, const T& paramValue, const char* message);
40 
41 protected: // overridden operations
42  Exception::Ptr Clone(void)const override;
43 
44 private: // deleted methods
45  ArgumentException& operator=(const ArgumentException& arg) = delete;
46 
47 private:
48  static const char* const defaultMessage;
49  static const char* const defaultMessage2;
50 };
51 
53 // inline methods of class ArgumentException
54 
56 template<typename... Args>
57 inline ArgumentException::ArgumentException(const char* message, const Args& ... args)
58  : CommonException(ExceptionTypeId::Argument, String::Format(message, args...))
59 {
60 }
61 
64  : CommonException(ExceptionTypeId::Argument, message)
65 {
66 }
67 
70  : CommonException(ExceptionTypeId::Argument, std::move(message))
71 {
72 }
73 
75 inline ArgumentException::ArgumentException(const String& message, const Exception& innerException)
76  : CommonException(ExceptionTypeId::Argument, message, innerException)
77 {
78 }
79 
81 inline ArgumentException::ArgumentException(String&& message, Exception&& innerException)
82  : CommonException(ExceptionTypeId::Argument, std::move(message), std::move(innerException))
83 {
84 }
85 
87 inline ArgumentException::ArgumentException(ExceptionTypeId typeId, const String& message, int skipStackTraceDepth)
88  : CommonException(typeId, std::move(message), skipStackTraceDepth)
89 {
90 }
91 
93 inline ArgumentException::ArgumentException(ExceptionTypeId typeId, String&& message, int skipStackTraceDepth)
94  : CommonException(typeId, std::move(message), skipStackTraceDepth)
95 {
96 }
97 
99 inline ArgumentException::ArgumentException(ExceptionTypeId typeId, const String& message, const Exception& innerException, int skipStackTraceDepth)
100  : CommonException(typeId, message, innerException, skipStackTraceDepth)
101 {
102 }
103 
105 inline ArgumentException::ArgumentException(ExceptionTypeId typeId, String&& message, Exception&& innerException, int skipStackTraceDepth)
106  : CommonException(typeId, std::move(message), std::move(innerException), skipStackTraceDepth)
107 {
108 }
109 
111 template<class T>
112 inline ArgumentException ArgumentException::Create(const char* paramName, const T& paramValue)
113 {
114  return ArgumentException(defaultMessage, paramName, paramValue);
115 }
116 
118 template<class T>
119 ArgumentException ArgumentException::Create(const char* paramName, const T& paramValue, const Exception& innerException)
120 {
121  return ArgumentException(String::Format(defaultMessage, paramName, paramValue), innerException);
122 }
123 
125 template<class T>
126 ArgumentException ArgumentException::Create(const char* paramName, const T& paramValue, const char* message)
127 {
128  return ArgumentException(String::Format(defaultMessage2, paramName, paramValue, message));
129 }
130 
131 }}} // end of namesapce Arp::System::Commons
This is the base class of common exception classes.
Definition: CommonException.hpp:18
static ArgumentException Create(const char *paramName, const T &paramValue)
Creates an ArgumentException instance using a default message text.
Definition: ArgumentException.hpp:112
String Format(int indentLevel, bool withInnerException) const override
Formats this exception using the given indent level.
Namespace of the C++ standard library
std::shared_ptr< Exception > Ptr
The smart pointer tpye of this class.
Definition: Exception.hpp:19
ExceptionTypeId
Specifies the type id of any exception derived by <see cref="CommonException".
Definition: ExceptionTypeId.hpp:14
This exception is used when an invalid argument occurs.
Definition: ArgumentException.hpp:14
Exception::Ptr Clone(void) const override
Clones this instance.
static SelfType Format(const SelfType &format, const Args &... args)
Formats the format string using the .NET/Python syntax with the given variadic arguments.
Definition: BasicString.hxx:1482
Root namespace for the PLCnext API
System components used by the System, Device, Plc or Io domains.
ArgumentException(const char *message, const Args &... args)
Constructs an ArgumentException instance.
Definition: ArgumentException.hpp:57
This is the base class of all Arp exception classes.
Definition: Exception.hpp:15