PLCnext API Documentation  22.9.0.33
ExceptionHandler.hxx
1 //
3 // Copyright PHOENIX CONTACT Electronics GmbH
4 //
6 #pragma once
7 #include "Arp/System/Core/Arp.h"
8 #include "Arp/System/Core/Exception.hpp"
9 #include "Arp/System/Commons/Logging.h"
10 
11 namespace Arp { namespace System { namespace Commons { namespace Testing
12 {
13 
15 class ExceptionHandler : private Loggable<ExceptionHandler>
16 {
17 public: // construction/destruction
19  ExceptionHandler(void) = delete;
21  ExceptionHandler(const ExceptionHandler& arg) = delete;
25  ~ExceptionHandler(void) = delete;
26 
27 public: // static operations
29  template<typename F>
30  static void ConvertToStd(F func);
31 };
32 
34 // inline methods of class ExceptionHandler
35 template<class F>
36 inline void ExceptionHandler::ConvertToStd(F func)
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.
ExceptionHandler & operator=(const ExceptionHandler &arg)=delete
Assignment operator.
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.
const BaseString & GetBaseString() const
Gets the basic std string.
Definition: BasicString.hxx:1501
@ System
System components used by the System, Device, Plc or Io domains.
Root namespace for the PLCnext API