VTK-m  2.1
Error.h
Go to the documentation of this file.
1 //============================================================================
2 // Copyright (c) Kitware, Inc.
3 // All rights reserved.
4 // See LICENSE.txt for details.
5 //
6 // This software is distributed WITHOUT ANY WARRANTY; without even
7 // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
8 // PURPOSE. See the above copyright notice for more information.
9 //============================================================================
10 #ifndef vtk_m_cont_Error_h
11 #define vtk_m_cont_Error_h
12 
13 // Note that this class and (most likely) all of its subclasses are not
14 // templated. If there is any reason to create a VTKm control library,
15 // this class and its subclasses should probably go there.
16 
17 #include <exception>
18 #include <string>
19 
20 #include <vtkm/cont/Logging.h>
21 
23 
24 namespace vtkm
25 {
26 namespace cont
27 {
28 
30 
33 class VTKM_ALWAYS_EXPORT Error : public std::exception
34 {
35 public:
36 //See note about GetMessage macro below.
37 #ifndef GetMessage
38  const std::string& GetMessage() const { return this->Message; }
40 #endif
41  const std::string& GetStackTrace() const { return this->StackTrace; }
43 
44 //GetMessage is a macro defined by <windows.h> to redirrect to
45 //GetMessageA or W depending on if you are using ansi or unicode.
46 //To get around this we make our own A/W variants on windows.
47 #ifdef _WIN32
48  const std::string& GetMessageA() const { return this->Message; }
49  const std::string& GetMessageW() const { return this->Message; }
50 #endif
51 
55  const char* what() const noexcept override { return this->What.c_str(); }
56 
60  bool GetIsDeviceIndependent() const { return this->IsDeviceIndependent; }
61 
62 protected:
64  : StackTrace(vtkm::cont::GetStackTrace(1))
65  , What("Undescribed error\n" + StackTrace)
66  , IsDeviceIndependent(false)
67  {
68  }
69  Error(const std::string& message, bool is_device_independent = false)
70  : Message(message)
71  , StackTrace(vtkm::cont::GetStackTrace(1))
72  , What(Message + "\n" + StackTrace)
73  , IsDeviceIndependent(is_device_independent)
74  {
75  }
76 
77  void SetMessage(const std::string& message)
78  {
79  this->Message = message;
80  this->What = this->Message + "\n" + this->StackTrace;
81  }
82 
83 private:
84  std::string Message;
85  std::string StackTrace;
86  std::string What;
88 };
89 
91 }
92 } // namespace vtkm::cont
93 
94 #endif //vtk_m_cont_Error_h
VTKM_SILENCE_WEAK_VTABLE_WARNING_START
#define VTKM_SILENCE_WEAK_VTABLE_WARNING_START
Definition: ExportMacros.h:119
vtkm
Groups connected points that have the same field value.
Definition: Atomic.h:19
vtkm::cont::Error::StackTrace
std::string StackTrace
Definition: Error.h:85
vtkm::cont::GetStackTrace
std::string GetStackTrace(vtkm::Int32 skip=0)
Returns a stacktrace on supported platforms.
VTKM_SILENCE_WEAK_VTABLE_WARNING_END
#define VTKM_SILENCE_WEAK_VTABLE_WARNING_END
Definition: ExportMacros.h:120
vtkm::cont::Error
The superclass of all exceptions thrown by any VTKm function or method.
Definition: Error.h:33
vtkm::cont::Error::What
std::string What
Definition: Error.h:86
vtkm::cont::Error::Message
std::string Message
Definition: Error.h:84
ExportMacros.h
vtkm::cont::Error::GetIsDeviceIndependent
bool GetIsDeviceIndependent() const
Returns true if this exception is device independent.
Definition: Error.h:60
vtkm::cont::Error::IsDeviceIndependent
bool IsDeviceIndependent
Definition: Error.h:87
vtkm::cont::Error::SetMessage
void SetMessage(const std::string &message)
Definition: Error.h:77
vtkm::cont::Error::what
const char * what() const noexcept override
Returns the message for the error and the stack trace for it.
Definition: Error.h:55
vtkm::cont::Error::Error
Error()
Definition: Error.h:63
VTKM_ALWAYS_EXPORT
#define VTKM_ALWAYS_EXPORT
Definition: ExportMacros.h:89
Logging.h
Logging utilities.
vtkm::cont::Error::Error
Error(const std::string &message, bool is_device_independent=false)
Definition: Error.h:69