PLCnext API Documentation 25.0.2.69
KeyNotFoundException.hpp
1
2//
3// Copyright Phoenix Contact GmbH & Co. KG
4//
6#pragma once
8#include "Arp/System/Commons/Exceptions/ArgumentException.hpp"
9
10namespace Arp { namespace System { namespace Commons
11{
12
15{
16public: // construction/destruction
17 template<typename... Args>
18 KeyNotFoundException(const char* message, const Args& ... args);
19 KeyNotFoundException(const String& message);
21 KeyNotFoundException(const String& message, const Exception& innerException);
22 KeyNotFoundException(String&& message, Exception&& innerException);
23 KeyNotFoundException(const KeyNotFoundException& arg) = default;
25 virtual ~KeyNotFoundException(void) = default;
26
27public: // static factory methods
28 template<class T>
29 static KeyNotFoundException Create(const T& keyValue);
30 template<class T>
31 static KeyNotFoundException Create(const T& keyValue, const Exception& innerException);
32
33protected: // overridden operations
34 Exception::Ptr Clone(void)const override;
35
36private: // deleted methods
37 KeyNotFoundException& operator=(const KeyNotFoundException& arg) = delete;
38
39private:
40 static const char* const defaultMessage;
41};
42
44// inline methods of class KeyNotFoundException
45
47template<typename... Args>
48inline KeyNotFoundException::KeyNotFoundException(const char* message, const Args& ... args)
49 : ArgumentException(ExceptionTypeId::KeyNotFound, String::Format(message, args...), StackCounter())
50{
51}
52
53
55template<class T>
57{
58 return KeyNotFoundException(defaultMessage, keyValue);
59}
60
62template<class T>
63inline KeyNotFoundException KeyNotFoundException::Create(const T& keyValue, const Exception& innerException)
64{
65 return KeyNotFoundException(String::Format(defaultMessage, keyValue), innerException);
66}
67
68}}} // end of namesapce Arp::System::Commons
69
71// template specialization of KeyNotFoundException formatter
72template<> struct fmt::formatter<Arp::System::Commons::KeyNotFoundException> : public fmt::ostream_formatter {};
This exception is thrown when an invalid argument occurs.
Definition: ArgumentException.hpp:17
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
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
This exception is thrown when a key of value does not exists inside a map.
Definition: KeyNotFoundException.hpp:15
static KeyNotFoundException Create(const T &keyValue)
Creates an KeyNotFoundException instance using a default message text.
Definition: KeyNotFoundException.hpp:56
KeyNotFoundException(const char *message, const Args &... args)
Constructs an KeyNotFoundException instance.
Definition: KeyNotFoundException.hpp:48
Exception::Ptr Clone(void) const override
This operation clones this instance polymorpically as a deep copy.
Definition: KeyNotFoundException.cpp:15
ExceptionTypeId
Specifies the type id of any exception derived by <see cref="CommonException".
Definition: ExceptionTypeId.hpp:15
Root namespace for the PLCnext API