LocalException.h
Go to the documentation of this file.
1 #pragma once
2 
4 
5 #include <exception>
6 #include <sstream>
7 #include <string>
8 
9 namespace armarx
10 {
20  class LocalException: public std::exception
21  {
22  public:
26  LocalException();
30  LocalException(const LocalException& e) noexcept;
34  LocalException(const std::string& reason) :
35  reason(reason), backtrace(""), output_buffer("")
36  {
37  backtrace = std::runtime_error(generateBacktrace());
38  setReason(reason);
39  }
40 
44  ~LocalException() noexcept override = default;
45 
49  const char* what() const noexcept override;
53  virtual std::string name() const
54  {
55  return "armarx::LocalException";
56  }
57 
61  void setReason(const std::string& reason);
62 
63 
67  std::string getReason() const;
68 
72  static std::string generateBacktrace();
73 
74  template<typename T>
75  LocalException& operator <<(const T& message)
76  {
77  std::stringstream ss;
78  ss << reason.what() << message;
79  reason = std::runtime_error(ss.str());
80  return *this;
81  }
82 
83  template<typename T>
84  LocalException& operator <<(const std::vector<T>& message)
85  {
86  // the operator <<(ostream, vector) is defined in two headers
87  // the implementations behave differently.
88  // here we explicitly select the operator we want
89  std::operator <<(std::stringstream(reason.what()), message);
90  return *this;
91  }
92 
93  private:
98  std::string generateOutputString() const;
103  std::runtime_error reason;
109  std::runtime_error backtrace;
110 
115  mutable std::runtime_error output_buffer;
116  };
118  "LocalException must be nothrow copy constructible");
119 
141  extern "C" void handleExceptions();
142 
158  std::string GetHandledExceptionString();
159 }
StringHelpers.h
armarx::GetHandledExceptionString
std::string GetHandledExceptionString()
Definition: Exception.cpp:147
cxxopts::value
std::shared_ptr< Value > value()
Definition: cxxopts.hpp:926
message
message(STATUS "Boost-Library-Dir: " "${Boost_LIBRARY_DIRS}") message(STATUS "Boost-LIBRARIES
Definition: CMakeLists.txt:8
std::operator<<
ARMARXCORE_IMPORT_EXPORT ostream & operator<<(ostream &stream, const armarx::RunningTaskIceBase &task)
std
Definition: Application.h:66
armarx::operator<<
std::ostream & operator<<(std::ostream &os, const PythonApplicationManager::Paths &paths)
Definition: PythonApplicationManager.cpp:221
T
float T
Definition: UnscentedKalmanFilterTest.cpp:35
armarx::handleExceptions
void handleExceptions()
Definition: Exception.cpp:141
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28