gtsam  4.1.0
gtsam
ThreadsafeException.h
1 /* ----------------------------------------------------------------------------
2 
3  * GTSAM Copyright 2010, Georgia Tech Research Corporation,
4  * Atlanta, Georgia 30332-0415
5  * All Rights Reserved
6  * Authors: Frank Dellaert, et al. (see THANKS for the full author list)
7 
8  * See LICENSE for the license information
9 
10  * -------------------------------------------------------------------------- */
11 
20 #pragma once
21 
22 #include <gtsam/config.h> // for GTSAM_USE_TBB
23 
24 #include <boost/optional/optional.hpp>
25 #include <gtsam/dllexport.h>
26 #include <string>
27 #include <typeinfo>
28 #include <exception>
29 
30 #ifdef GTSAM_USE_TBB
31 #include <tbb/tbb_allocator.h>
32 #include <tbb/scalable_allocator.h>
33 #include <iostream>
34 #endif
35 
36 namespace gtsam {
37 
39 template<class DERIVED>
41 public std::exception
42 {
43 private:
44  typedef std::exception Base;
45 #ifdef GTSAM_USE_TBB
46 protected:
47  typedef std::basic_string<char, std::char_traits<char>,
48  tbb::tbb_allocator<char> > String;
49 #else
50 protected:
51  typedef std::string String;
52 #endif
53 
54 protected:
55  bool dynamic_;
56  mutable boost::optional<String> description_;
57 
60  dynamic_(false) {
61  }
62 
65  Base(other), dynamic_(false) {
66  }
67 
69  ThreadsafeException(const std::string& description) :
70  dynamic_(false), description_(
71  String(description.begin(), description.end())) {
72  }
73 
75  virtual ~ThreadsafeException() noexcept {
76  }
77 
78 public:
79  const char* what() const noexcept override {
80  return description_ ? description_->c_str() : "";
81  }
82 };
83 
85 class GTSAM_EXPORT RuntimeErrorThreadsafe: public ThreadsafeException<RuntimeErrorThreadsafe> {
86 public:
88  RuntimeErrorThreadsafe(const std::string& description) :
90  }
91 };
92 
94 class OutOfRangeThreadsafe: public ThreadsafeException<OutOfRangeThreadsafe> {
95 public:
97  OutOfRangeThreadsafe(const std::string& description) :
99  }
100 };
101 
104  InvalidArgumentThreadsafe> {
105 public:
107  InvalidArgumentThreadsafe(const std::string& description) :
109  }
110 };
111 
113 class CholeskyFailed : public gtsam::ThreadsafeException<CholeskyFailed>
114 {
115 public:
116  CholeskyFailed() noexcept {}
117  virtual ~CholeskyFailed() noexcept {}
118 };
119 
120 } // namespace gtsam
gtsam::ThreadsafeException::description_
boost::optional< String > description_
Optional description.
Definition: ThreadsafeException.h:56
gtsam::RuntimeErrorThreadsafe::RuntimeErrorThreadsafe
RuntimeErrorThreadsafe(const std::string &description)
Construct with a string describing the exception.
Definition: ThreadsafeException.h:88
gtsam::OutOfRangeThreadsafe
Thread-safe out of range exception.
Definition: ThreadsafeException.h:94
gtsam::OutOfRangeThreadsafe::OutOfRangeThreadsafe
OutOfRangeThreadsafe(const std::string &description)
Construct with a string describing the exception.
Definition: ThreadsafeException.h:97
gtsam::ThreadsafeException::ThreadsafeException
ThreadsafeException(const ThreadsafeException &other)
Copy constructor is protected - may only be created from derived classes.
Definition: ThreadsafeException.h:64
gtsam::CholeskyFailed
Indicate Cholesky factorization failure.
Definition: ThreadsafeException.h:114
gtsam
Global functions in a separate testing namespace.
Definition: chartTesting.h:28
gtsam::ThreadsafeException::ThreadsafeException
ThreadsafeException(const std::string &description)
Construct with description string.
Definition: ThreadsafeException.h:69
gtsam::ThreadsafeException::~ThreadsafeException
virtual ~ThreadsafeException() noexcept
Default destructor doesn't have the noexcept.
Definition: ThreadsafeException.h:75
gtsam::InvalidArgumentThreadsafe::InvalidArgumentThreadsafe
InvalidArgumentThreadsafe(const std::string &description)
Construct with a string describing the exception.
Definition: ThreadsafeException.h:107
gtsam::ThreadsafeException::dynamic_
bool dynamic_
Whether this object was moved.
Definition: ThreadsafeException.h:55
gtsam::InvalidArgumentThreadsafe
Thread-safe invalid argument exception.
Definition: ThreadsafeException.h:104
gtsam::RuntimeErrorThreadsafe
Thread-safe runtime error exception.
Definition: ThreadsafeException.h:85
gtsam::ThreadsafeException::ThreadsafeException
ThreadsafeException()
Default constructor is protected - may only be created from derived classes.
Definition: ThreadsafeException.h:59
gtsam::ThreadsafeException
Base exception type that uses tbb_allocator if GTSAM is compiled with TBB.
Definition: ThreadsafeException.h:42