PLCnext API Documentation 23.6.0.37
ExceptionHandler.hxx
1
2//
3// Copyright PHOENIX CONTACT Electronics GmbH
4//
6#pragma once
8#include "Arp/System/Core/Exception.hpp"
9#include "Arp/System/Commons/Logging.h"
10
11namespace Arp { namespace System { namespace Commons { namespace Testing
12{
13
15class ExceptionHandler : private Loggable<ExceptionHandler>
16{
17public: // construction/destruction
19 ExceptionHandler(void) = delete;
21 ExceptionHandler(const ExceptionHandler& arg) = delete;
25 ~ExceptionHandler(void) = delete;
26
27public: // static operations
29 template<typename F>
30 static void ConvertToStd(F func);
31};
32
34// inline methods of class ExceptionHandler
35template<class F>
37{
38 try
39 {
40 func();
41 }
42 catch (const Arp::Exception& e)
43 {
44 log.Error("Exception in unit test occurs: {}", e);
45 throw std::runtime_error(e.ToString().GetBaseString());
46 }
47}
48}}}} // end of namespace Arp::System::Commons::Testing
This is the base class of all Arp exception classes.
Definition: Exception.hpp:16
String ToString(void) const
Gets a reasonable string representation of this exception.
Static exception handler class for easy use in unit tests.
Definition: ExceptionHandler.hxx:16
~ExceptionHandler(void)=delete
Destructs this instance and frees all resources.
static void ConvertToStd(F func)
Converts Arp exception to std exceptions, which might be handled by boost test framework.
Definition: ExceptionHandler.hxx:36
ExceptionHandler(void)=delete
Constructs an ExceptionHandler instance.
ExceptionHandler(const ExceptionHandler &arg)=delete
Copy constructor.
ExceptionHandler & operator=(const ExceptionHandler &arg)=delete
Assignment operator.
const BaseString & GetBaseString() const
Gets the basic std string.
Definition: BasicString.hxx:1511
@ System
System components used by the System, Device, Plc or Io domains.
Root namespace for the PLCnext API