VTK-m  1.9
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; }
39 #endif
40  const std::string& GetStackTrace() const { return this->StackTrace; }
41 
42 //GetMessage is a macro defined by <windows.h> to redirrect to
43 //GetMessageA or W depending on if you are using ansi or unicode.
44 //To get around this we make our own A/W variants on windows.
45 #ifdef _WIN32
46  const std::string& GetMessageA() const { return this->Message; }
47  const std::string& GetMessageW() const { return this->Message; }
48 #endif
49 
50  // For std::exception compatibility:
51  const char* what() const noexcept override { return this->What.c_str(); }
52 
56  bool GetIsDeviceIndependent() const { return this->IsDeviceIndependent; }
57 
58 protected:
60  : StackTrace(vtkm::cont::GetStackTrace(1))
61  , What("Undescribed error\n" + StackTrace)
62  , IsDeviceIndependent(false)
63  {
64  }
65  Error(const std::string& message, bool is_device_independent = false)
66  : Message(message)
67  , StackTrace(vtkm::cont::GetStackTrace(1))
68  , What(Message + "\n" + StackTrace)
69  , IsDeviceIndependent(is_device_independent)
70  {
71  }
72 
73  void SetMessage(const std::string& message)
74  {
75  this->Message = message;
76  this->What = this->Message + "\n" + this->StackTrace;
77  }
78 
79 private:
80  std::string Message;
81  std::string StackTrace;
82  std::string What;
84 };
85 
87 }
88 } // namespace vtkm::cont
89 
90 #endif //vtk_m_cont_Error_h
VTKM_SILENCE_WEAK_VTABLE_WARNING_START
#define VTKM_SILENCE_WEAK_VTABLE_WARNING_START
Definition: ExportMacros.h:119
vtkm
VTKM_NO_DEPRECATED_VIRTUAL.
Definition: Algorithms.h:18
vtkm::cont::Error::StackTrace
std::string StackTrace
Definition: Error.h:81
vtkm::cont::GetStackTrace
VTKM_CONT_EXPORT VTKM_CONT 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:82
vtkm::cont::Error::Message
std::string Message
Definition: Error.h:80
ExportMacros.h
vtkm::cont::Error::GetIsDeviceIndependent
bool GetIsDeviceIndependent() const
Returns true if this exception is device independent.
Definition: Error.h:56
vtkm::cont::Error::IsDeviceIndependent
bool IsDeviceIndependent
Definition: Error.h:83
vtkm::cont::Error::SetMessage
void SetMessage(const std::string &message)
Definition: Error.h:73
vtkm::cont::Error::what
const char * what() const noexcept override
Definition: Error.h:51
vtkm::cont::Error::GetMessage
const std::string & GetMessage() const
Definition: Error.h:38
vtkm::cont::Error::Error
Error()
Definition: Error.h:59
vtkm::cont::Error::GetStackTrace
const std::string & GetStackTrace() const
Definition: Error.h:40
VTKM_ALWAYS_EXPORT
#define VTKM_ALWAYS_EXPORT
Definition: ExportMacros.h:92
Logging.h
Logging utilities.
vtkm::cont::Error::Error
Error(const std::string &message, bool is_device_independent=false)
Definition: Error.h:65