HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
HOM_Errors.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * COMMENTS:
7  */
8 
9 #ifndef __HOM_Errors_h__
10 #define __HOM_Errors_h__
11 
12 #include "HOM_API.h"
13 #include "HOM_Defines.h"
14 #include <string>
15 
16 // HOM_SystemExit is a special exception that gets translated into a python
17 // SystemExit exception via swig typemaps. hou.exit() will raise a
18 // SystemExit exception, much like sys.exit() does, to unroll out of the
19 // python call stack.
20 SWIGOUT(%exceptionclass HOM_SystemExit;)
21 SWIGOUT(%rename(SystemExit) HOM_SystemExit;)
23 {
24 public:
25  HOM_SystemExit(int exit_code)
26  : myExitCode(exit_code)
27  {}
28 
29  int code()
30  { return myExitCode; }
31 
32 private:
33  int myExitCode;
34 };
35 
36 
37 // This is the base class for all HOM error exceptions. Having a base class
38 // makes it easier to catch HOM error exceptions, both in C++ (from Houdini)
39 // and in scripting languages.
40 SWIGOUT(%exceptionclass HOM_Error;)
41 // HOM_Error::clone() should only be useful in C++ context, and doesn't need to
42 // be wrapped by SWIG. Ignoring the clone() method in the base class will also
43 // ignore the clone() method in the derived classes.
47 {
48 public:
49  HOM_Error(const char *instance_message = "")
50  : myInstanceMessage(instance_message ? instance_message : "")
51  {}
52 
53  virtual ~HOM_Error()
54  {}
55 
56  // Suppress SWIG warnings about copy operators being ignored
57 #ifndef SWIG
58  HOM_Error(const HOM_Error &src) = default;
59  HOM_Error &operator=(const HOM_Error &src) = default;
60 #endif
61 
62  virtual HOM_Error* clone() { return new HOM_Error(*this); }
63 
64  virtual std::string exceptionTypeName() { return "Error"; }
65 
66  virtual std::string description() { return ""; }
67 
68  virtual std::string instanceMessage() { return myInstanceMessage; }
69 
70  std::string __repr__()
71  {
72  std::string result = "<hou.";
73  result += exceptionTypeName();
74  result += ">";
75  return result;
76  }
77 
78  std::string __str__()
79  {
80  std::string result;
81  if (description().size())
82  {
83  result += description();
84  result += ".";
85  }
86  std::string instance_msg = instanceMessage();
87  if (instance_msg.size())
88  {
89  if (description().size())
90  result += "\n";
91  result += instance_msg;
92  }
93  return result;
94  }
95 
96 private:
97  std::string myInstanceMessage;
98 };
99 
100 // We tell swig that each subclass overrides __repr__. Otherwise, swig
101 // will create its own __repr__ for each subclass and won't call the base
102 // class's one.
103 #define SIMPLE_EXCEPTION(exception_name, description_value) \
104 SWIGOUT(%rename(exception_name) HOM_ ## exception_name;) \
105 class HOM_API HOM_ ## exception_name : public HOM_Error \
106 { \
107 public: \
108  HOM_ ## exception_name(const char* instance_message = "") \
109  : HOM_Error(instance_message) \
110  {} \
111  HOM_Error* clone() override { return new HOM_ ## exception_name(*this); } \
112  std::string exceptionTypeName() override { return #exception_name; } \
113  std::string description() override { return description_value; } \
114  SWIGOUT(std::string __repr__();) \
115  SWIGOUT(std::string __str__();) \
116 };
117 
118 #define INTERNAL_EXCEPTION(exception_name, description_value) \
119 SWIGOUT(%ignore HOM_ ## exception_name;) \
120 class HOM_API HOM_ ## exception_name : public HOM_Error \
121 { \
122 public: \
123  HOM_ ## exception_name(const char* instance_message = "") \
124  : HOM_Error(instance_message) \
125  {} \
126  HOM_Error* clone() override { return new HOM_ ## exception_name(*this); } \
127  std::string exceptionTypeName() override { return #exception_name; } \
128  std::string description() override { return description_value; } \
129 };
130 
131 
132 // Use DERIVED_EXCEPTION when you wish to add a python exception that inherits
133 // from an existing one. This helps to maintain backward compatiblity for
134 // existing python code that already checks for the base_exception as this will
135 // still be caught in the try/except block whilst allowing newer code to perform
136 // more fine-grained checks.
137 
138 #define DERIVED_EXCEPTION(exception_name, base_exception, description_value) \
139 SWIGOUT(%rename(exception_name) HOM_ ## exception_name;) \
140 class HOM_API HOM_ ## exception_name : public HOM_ ## base_exception \
141 { \
142 public: \
143  HOM_ ## exception_name(const char* instance_message = "") \
144  : HOM_ ## base_exception(instance_message) \
145  {} \
146  HOM_Error* clone() override { return new HOM_ ## exception_name(*this); } \
147  std::string exceptionTypeName() override { return #exception_name; } \
148  std::string description() override { return description_value; } \
149  SWIGOUT(std::string __repr__();) \
150  SWIGOUT(std::string __str__();) \
151 };
152 
153 #define SIMPLE_EXCEPTION_DFLT_INSTANCE(exception_name, description_value, \
154  default_instance_value) \
155 SWIGOUT(%rename(exception_name) HOM_ ## exception_name;) \
156 class HOM_API HOM_ ## exception_name : public HOM_Error \
157 { \
158 public: \
159  HOM_ ## exception_name(const char* instance_message = "") \
160  : HOM_Error(instance_message) \
161  {} \
162  HOM_Error* clone() override { return new HOM_ ## exception_name(*this); } \
163  std::string exceptionTypeName() override { return #exception_name; } \
164  std::string description() override { return description_value; } \
165  std::string instanceMessage() override \
166  { \
167  std::string instance_msg = HOM_Error::instanceMessage(); \
168  if (!instance_msg.size()) instance_msg = default_instance_value; \
169  return instance_msg; \
170  } \
171  SWIGOUT(std::string __repr__();) \
172  SWIGOUT(std::string __str__();) \
173 };
174 
175 SIMPLE_EXCEPTION(NotAvailable,
176  "Not available in this context")
177 SIMPLE_EXCEPTION(ObjectWasDeleted,
178  "Attempt to access an object that no longer exists in Houdini")
179 SIMPLE_EXCEPTION(InvalidInput,
180  "Invalid input")
181 SIMPLE_EXCEPTION(InvalidOutput,
182  "Invalid output")
183 SIMPLE_EXCEPTION(InvalidSize,
184  "Invalid size")
185 INTERNAL_EXCEPTION(TypeError,
186  "Invalid type")
187 INTERNAL_EXCEPTION(ValueError,
188  "Invalid value")
189 SIMPLE_EXCEPTION(OperationFailed,
190  "The attempted operation failed")
191 SIMPLE_EXCEPTION(InvalidNodeType,
192  "The node type is invalid")
193 SIMPLE_EXCEPTION(InitScriptFailed,
194  "Node initialization script failed")
195 SIMPLE_EXCEPTION(MatchDefinitionError,
196  "Failed to match node type definition")
197 SIMPLE_EXCEPTION_DFLT_INSTANCE(PermissionError, "",
198  "Failed to modify node or parameter because of a permission "
199  "error. Possible causes include locked assets, takes, "
200  "product permissions or user specified permissions")
201 SIMPLE_EXCEPTION(GeometryPermissionError,
202  "Geometry is read-only")
203 SIMPLE_EXCEPTION(KeyframeValueNotSet,
204  "This keyframe value is not set")
205 SIMPLE_EXCEPTION(OperationInterrupted,
206  "The requested operation was interrupted")
207 SIMPLE_EXCEPTION(LoadWarning,
208  "Warnings were generated during load")
209 SIMPLE_EXCEPTION(NodeError,
210  "Error generated by Python node")
211 SIMPLE_EXCEPTION(NodeWarning,
212  "Warning generated by Python node")
213 SIMPLE_EXCEPTION(NameConflict,
214  "Name conflict was detected")
215 SIMPLE_EXCEPTION(TypeConflict,
216  "Type conflict was detected")
217 SIMPLE_EXCEPTION(StateNotRegistered,
218  "Attempt to unregister a non-registered state")
219 SIMPLE_EXCEPTION(HandleNotRegistered,
220  "Attempt to unregister a non-registered handle")
221 SIMPLE_EXCEPTION(LicenseError, "Not available in current session")
222 
223 DERIVED_EXCEPTION(InvalidGeometry, OperationFailed,
224  "The underlying geometry is not valid. Possibly caused "
225  "by the source SOP Node failing to cook since the python "
226  "geometry was assigned.")
227 
228 #endif
virtual std::string exceptionTypeName()
Definition: HOM_Errors.h:64
std::string __str__()
Definition: HOM_Errors.h:78
#define INTERNAL_EXCEPTION(exception_name, description_value)
Definition: HOM_Errors.h:118
Definition: ImfName.h:28
#define SIMPLE_EXCEPTION(exception_name, description_value)
Definition: HOM_Errors.h:103
Attempt to access an object that no longer exists in Houdini Invalid output Invalid type The attempted operation failed Node initialization script failed Failed to modify node or parameter because of a permission error Possible causes include locked assets
Definition: HOM_Errors.h:197
Definition: Node.h:52
GLsizei const GLfloat * value
Definition: glcorearb.h:824
HOM_Error(const char *instance_message="")
Definition: HOM_Errors.h:49
#define SWIGOUT(x)
Definition: HOM_Defines.h:24
virtual HOM_Error * clone()
Definition: HOM_Errors.h:62
GLboolean GLboolean GLboolean GLboolean a
Definition: glcorearb.h:1222
**But if you need a result
Definition: thread.h:622
constexpr auto underlying(Enum e) noexcept-> underlying_t< Enum >
Definition: format.h:4354
#define DERIVED_EXCEPTION(exception_name, base_exception, description_value)
Definition: HOM_Errors.h:138
constexpr auto in(type t, int set) -> bool
Definition: core.h:611
< returns > If no error
Definition: snippets.dox:2
GLint GLint GLsizei GLint GLenum GLenum type
Definition: glcorearb.h:108
#define HOM_API
Definition: HOM_API.h:13
void ignore(T const &) VULKAN_HPP_NOEXCEPT
Definition: vulkan.hpp:6508
GLuint GLint GLboolean GLint GLenum access
Definition: glcorearb.h:2222
constexpr auto set(type rhs) -> int
Definition: core.h:610
ApexGeometry Geometry
Definition: APEX_Include.h:69
GLsizei GLsizei GLchar * source
Definition: glcorearb.h:803
virtual std::string instanceMessage()
Definition: HOM_Errors.h:68
std::string __repr__()
Definition: HOM_Errors.h:70
OIIO_UTIL_API bool exists(string_view path) noexcept
Attempt to access an object that no longer exists in Houdini Invalid output Invalid type The attempted operation failed Node initialization script failed Failed to modify node or parameter because of a permission error Possible causes include locked takes
Definition: HOM_Errors.h:197
GLsizeiptr size
Definition: glcorearb.h:664
Error
Definition: oidn.hpp:578
OIIO_UTIL_API bool rename(string_view from, string_view to, std::string &err)
virtual ~HOM_Error()
Definition: HOM_Errors.h:53
LeafData & operator=(const LeafData &)=delete
#define SIMPLE_EXCEPTION_DFLT_INSTANCE(exception_name, description_value, default_instance_value)
Definition: HOM_Errors.h:153
HOM_SystemExit(int exit_code)
Definition: HOM_Errors.h:25
state
Definition: core.h:2289
virtual std::string description()
Definition: HOM_Errors.h:66
GLenum src
Definition: glcorearb.h:1793