Viskores  1.0
Error.h
Go to the documentation of this file.
1 //============================================================================
2 // The contents of this file are covered by the Viskores license. See
3 // LICENSE.txt for details.
4 //
5 // By contributing to this file, all contributors agree to the Developer
6 // Certificate of Origin Version 1.1 (DCO 1.1) as stated in DCO.txt.
7 //============================================================================
8 
9 //============================================================================
10 // Copyright (c) Kitware, Inc.
11 // All rights reserved.
12 // See LICENSE.txt for details.
13 //
14 // This software is distributed WITHOUT ANY WARRANTY; without even
15 // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
16 // PURPOSE. See the above copyright notice for more information.
17 //============================================================================
18 #ifndef viskores_cont_Error_h
19 #define viskores_cont_Error_h
20 
21 // Note that this class and (most likely) all of its subclasses are not
22 // templated. If there is any reason to create a Viskores control library,
23 // this class and its subclasses should probably go there.
24 
25 #include <exception>
26 #include <string>
27 
28 #include <viskores/cont/Logging.h>
29 
31 
32 namespace viskores
33 {
34 namespace cont
35 {
36 
38 
41 class VISKORES_ALWAYS_EXPORT Error : public std::exception
42 {
43 public:
44 //See note about GetMessage macro below.
45 #ifndef GetMessage
46  const std::string& GetMessage() const { return this->Message; }
48 #endif
49  const std::string& GetStackTrace() const { return this->StackTrace; }
51 
52 //GetMessage is a macro defined by <windows.h> to redirrect to
53 //GetMessageA or W depending on if you are using ansi or unicode.
54 //To get around this we make our own A/W variants on windows.
55 #ifdef _WIN32
56  const std::string& GetMessageA() const { return this->Message; }
57  const std::string& GetMessageW() const { return this->Message; }
58 #endif
59 
63  const char* what() const noexcept override { return this->What.c_str(); }
64 
68  bool GetIsDeviceIndependent() const { return this->IsDeviceIndependent; }
69 
70 protected:
72  : StackTrace(viskores::cont::GetStackTrace(1))
73  , What("Undescribed error\n" + StackTrace)
74  , IsDeviceIndependent(false)
75  {
76  }
77  Error(const std::string& message, bool is_device_independent = false)
78  : Message(message)
79  , StackTrace(viskores::cont::GetStackTrace(1))
80  , What(Message + "\n" + StackTrace)
81  , IsDeviceIndependent(is_device_independent)
82  {
83  }
84 
85  void SetMessage(const std::string& message)
86  {
87  this->Message = message;
88  this->What = this->Message + "\n" + this->StackTrace;
89  }
90 
91 private:
92  std::string Message;
93  std::string StackTrace;
94  std::string What;
96 };
97 
99 }
100 } // namespace viskores::cont
101 
102 #endif //viskores_cont_Error_h
viskores::cont::Error::IsDeviceIndependent
bool IsDeviceIndependent
Definition: Error.h:95
viskores::cont::Error::What
std::string What
Definition: Error.h:94
viskores::cont::Error::Error
Error()
Definition: Error.h:71
viskores::cont::Error::Error
Error(const std::string &message, bool is_device_independent=false)
Definition: Error.h:77
ExportMacros.h
viskores::cont::Error::StackTrace
std::string StackTrace
Definition: Error.h:93
viskores
Groups connected points that have the same field value.
Definition: Atomic.h:27
viskores::cont::GetStackTrace
std::string GetStackTrace(viskores::Int32 skip=0)
Returns a stacktrace on supported platforms.
VISKORES_SILENCE_WEAK_VTABLE_WARNING_END
#define VISKORES_SILENCE_WEAK_VTABLE_WARNING_END
Definition: ExportMacros.h:128
viskores::cont::Error::SetMessage
void SetMessage(const std::string &message)
Definition: Error.h:85
VISKORES_SILENCE_WEAK_VTABLE_WARNING_START
#define VISKORES_SILENCE_WEAK_VTABLE_WARNING_START
Definition: ExportMacros.h:127
viskores::cont::Error::what
const char * what() const noexcept override
Returns the message for the error and the stack trace for it.
Definition: Error.h:63
viskores::cont::Error::Message
std::string Message
Definition: Error.h:92
viskores::cont::Error::GetIsDeviceIndependent
bool GetIsDeviceIndependent() const
Returns true if this exception is device independent.
Definition: Error.h:68
viskores::cont::Error
The superclass of all exceptions thrown by any Viskores function or method.
Definition: Error.h:41
Logging.h
Logging utilities.