PLCnext API Documentation 25.0.2.69
JsonException.hpp
1
2//
3// Copyright Phoenix Contact GmbH & Co. KG
4//
6#pragma once
8#include "Arp/System/Commons/Exceptions/CommonException.hpp"
9
10namespace Arp { namespace System { namespace Commons
11{
12
15{
16public: // construction/destruction
17 template<typename... Args>
18 JsonException(const char* message, const Args& ... args);
19 explicit JsonException(const String& message);
20 explicit JsonException(String&& message);
21 JsonException(const String& message, const Exception& innerException);
22 JsonException(String&& message, Exception&& innerException);
23 JsonException(const JsonException& arg) = default;
24 JsonException(JsonException&& arg) = default;
25 ~JsonException(void)override = default;
26
27public: // static factory methods
28 static JsonException Create(void);
29 static JsonException Create(const Exception& innerException);
30 template<typename... Args>
31 static JsonException Create(const char* filename, const char* message, const Args& ... args);
32
33protected: // overridden operations
34 Exception::Ptr Clone(void)const override;
35
36private: // deleted methods
37 JsonException& operator=(const JsonException& arg) = delete;
38
39private:
40 static const char* const defaultMessage;
41 static const char* const fileLineMessage;
42};
43
45// inline methods of class JsonException
46
48template<typename... Args>
49inline JsonException::JsonException(const char* message, const Args& ... args)
50 : CommonException(ExceptionTypeId::Json, String::Format(message, args...))
51{
52}
53
54template<typename... Args>
55inline JsonException JsonException::Create(const char* filename, const char* message, const Args& ... args)
56{
57 return JsonException(String::Format(fileLineMessage, String::Format(message, args...), filename));
58}
59
60}}} // end of namesapce Arp::System::Commons
61
63// template specialization of JsonException formatter
64template<> struct fmt::formatter<Arp::System::Commons::JsonException> : public fmt::ostream_formatter {};
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 is the base class of common exception classes.
Definition: CommonException.hpp:18
This exception is used for Json parsing errors.
Definition: JsonException.hpp:15
JsonException(const char *message, const Args &... args)
Constructs an JsonException instance.
Definition: JsonException.hpp:49
Exception::Ptr Clone(void) const override
This operation clones this instance polymorpically as a deep copy.
Definition: JsonException.cpp:17
static JsonException Create(void)
Creates an JsonException instance using a default message text.
Definition: JsonException.cpp:47
ExceptionTypeId
Specifies the type id of any exception derived by <see cref="CommonException".
Definition: ExceptionTypeId.hpp:15
Root namespace for the PLCnext API