PLCnext API Documentation 25.0.2.69
ArgumentException.hpp
1
2//
3// Copyright Phoenix Contact GmbH & Co. KG
4//
6#pragma once
8#include "Arp/Base/Core/PimplPtr.hxx"
9#include "Arp/Base/Commons/Exceptions/CommonExceptionBase.hpp"
10
11namespace Arp::Base::Commons::Exceptions
12{
13
16class ARP_BASE_COMMONS_EXPORT ArgumentException : public CommonExceptionBase
17{
18public: // Impl forward declaration
19 class Impl;
20
21public: // canonical construction/destruction/assignment
26 ~ArgumentException(void)override;
27
28public: // construction
29 template<typename... Args>
30 explicit ArgumentException(const char* message, const Args& ... args);
31 ArgumentException(String&& message);
32 ArgumentException(const String& message);
33 ArgumentException(String&& message, const Exception& innerException);
34 ArgumentException(const String& message, const Exception& innerException);
35
36protected: // construction for derived exceptions
37 ArgumentException(ExceptionTypeId typeId, String&& message, StackCounter stackCounter);
38 ArgumentException(ExceptionTypeId typeId, const String& message, StackCounter stackCounter);
39 ArgumentException(ExceptionTypeId typeId, String&& message, const Exception& innerException, StackCounter stackCounter);
40 ArgumentException(ExceptionTypeId typeId, const String& message, const Exception& innerException, StackCounter stackCounter);
41
42public: // static factory operations
43 template<class T>
44 static ArgumentException Create(const char* paramName, const T& paramValue);
45 template<class T>
46 static ArgumentException Create(const char* paramName, const T& paramValue, const char* message);
47 template<class T>
48 static ArgumentException Create(const char* paramName, const T& paramValue, const Exception& innerException);
49
50public: // internal operations
51 Impl& GetImpl(void);
52 const Impl& GetImpl(void)const;
53
54protected: // overridden operations
55 Exception::Ptr Clone(void)const override;
56
57private: // static factory methods
58 static ArgumentException CreateImpl(const char* paramName, const String& paramValue, StackCounter stackCounter);
59 static ArgumentException CreateImpl(const char* paramName, const String& paramValue, const char* message, StackCounter stackCounter);
60 static ArgumentException CreateImpl(const char* paramName, const String& paramValue, const Exception& innerException, StackCounter stackCounter);
61
62private: // Impl usings
64
65private: // Impl fields
66 Pimpl pimpl;
67};
68
70// inline methods of class ArgumentException
71
78template<typename... Args>
79inline ArgumentException::ArgumentException(const char* message, const Args& ... args)
80 : ArgumentException(ExceptionTypeId::Argument, String::Format(message, args...), StackCounter())
81{
82}
83
91template<class T>
92inline ArgumentException ArgumentException::Create(const char* paramName, const T& paramValue)
93{
94 return CreateImpl(paramName, String::Format("{}", paramValue), StackCounter());
95}
96
105template<class T>
106inline ArgumentException ArgumentException::Create(const char* paramName, const T& paramValue, const char* message)
107{
108 return CreateImpl(paramName, String::Format("{}", paramValue), message, StackCounter());
109}
110
118template<class T>
119inline ArgumentException ArgumentException::Create(const char* paramName, const T& paramValue, const Exception& innerException)
120{
121 return CreateImpl(paramName, String::Format("{}", paramValue), innerException, StackCounter());
122}
123
124} // end of namespace Arp::Base::Commons::Exceptions
125
126namespace Arp {
127// Import exception into Arp namespace as Arp::System::Commons library does
129} // end of namespace Arp
131// template specialization of ArgumentException formatter
132template<> struct fmt::formatter<Arp::Base::Commons::Exceptions::ArgumentException> : public fmt::ostream_formatter {};
This exception is thrown when an invalid argument occurs.
Definition: ArgumentException.hpp:17
~ArgumentException(void) override
Default destructor.
ArgumentException(ArgumentException &&arg) noexcept
Default move constructor.
ArgumentException & operator=(const ArgumentException &arg)
Default copy-assignment operator.
static ArgumentException Create(const char *paramName, const T &paramValue)
Creates an ArgumentException using a default message.
Definition: ArgumentException.hpp:92
ArgumentException & operator=(ArgumentException &&arg) noexcept
Default move-assignment operator.
ArgumentException(const ArgumentException &arg)
Default copy constructor.
This class serves as base class for all Arp commons exceptions.
Definition: CommonExceptionBase.hpp:24
This class is used to count sequenced operation calls, which are e.g. invoked during an exception thr...
Definition: StackCounter.hpp:20
This is the base class of all Arp exception classes.
Definition: Exception.hpp:21
std::unique_ptr< Exception > Ptr
The smart pointer type of this class.
Definition: Exception.hpp:27
Adapter class to implement PImpl idiom.
Definition: PimplPtr.hxx:15
This class represents the Arp String. The implementation is based on std::string.
Definition: String.hpp:39
static String Format(const String &format, const Args &... args)
Formats the format string using the .NET/Python syntax with the given variadic arguments.
Definition: String.inl:18
@ 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