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  virtual HOM_Error* clone() { return new HOM_Error(*this); } \
57 
58  virtual std::string exceptionTypeName() { return "Error"; }
59 
60  virtual std::string description() { return ""; }
61 
62  virtual std::string instanceMessage() { return myInstanceMessage; }
63 
65  {
66  std::string result = "<hou.";
67  result += exceptionTypeName();
68  result += ">";
69  return result;
70  }
71 
73  {
75  if (description().size())
76  {
77  result += description();
78  result += ".";
79  }
80  std::string instance_msg = instanceMessage();
81  if (instance_msg.size())
82  {
83  if (description().size())
84  result += "\n";
85  result += instance_msg;
86  }
87  return result;
88  }
89 
90 private:
91  std::string myInstanceMessage;
92 };
93 
94 // We tell swig that each subclass overrides __repr__. Otherwise, swig
95 // will create its own __repr__ for each subclass and won't call the base
96 // class's one.
97 #define SIMPLE_EXCEPTION(exception_name, description_value) \
98 SWIGOUT(%rename(exception_name) HOM_ ## exception_name;) \
99 class HOM_API HOM_ ## exception_name : public HOM_Error \
100 { \
101 public: \
102  HOM_ ## exception_name(const char* instance_message = "") \
103  : HOM_Error(instance_message) \
104  {} \
105  HOM_Error* clone() override { return new HOM_ ## exception_name(*this); } \
106  std::string exceptionTypeName() override { return #exception_name; } \
107  std::string description() override { return description_value; } \
108  SWIGOUT(std::string __repr__();) \
109  SWIGOUT(std::string __str__();) \
110 };
111 
112 #define INTERNAL_EXCEPTION(exception_name, description_value) \
113 SWIGOUT(%ignore HOM_ ## exception_name;) \
114 class HOM_API HOM_ ## exception_name : public HOM_Error \
115 { \
116 public: \
117  HOM_ ## exception_name(const char* instance_message = "") \
118  : HOM_Error(instance_message) \
119  {} \
120  HOM_Error* clone() override { return new HOM_ ## exception_name(*this); } \
121  std::string exceptionTypeName() override { return #exception_name; } \
122  std::string description() override { return description_value; } \
123 };
124 
125 
126 // Use DERIVED_EXCEPTION when you wish to add a python exception that inherits
127 // from an existing one. This helps to maintain backward compatiblity for
128 // existing python code that already checks for the base_exception as this will
129 // still be caught in the try/except block whilst allowing newer code to perform
130 // more fine-grained checks.
131 
132 #define DERIVED_EXCEPTION(exception_name, base_exception, description_value) \
133 SWIGOUT(%rename(exception_name) HOM_ ## exception_name;) \
134 class HOM_API HOM_ ## exception_name : public HOM_ ## base_exception \
135 { \
136 public: \
137  HOM_ ## exception_name(const char* instance_message = "") \
138  : HOM_ ## base_exception(instance_message) \
139  {} \
140  HOM_Error* clone() override { return new HOM_ ## exception_name(*this); } \
141  std::string exceptionTypeName() override { return #exception_name; } \
142  std::string description() override { return description_value; } \
143  SWIGOUT(std::string __repr__();) \
144  SWIGOUT(std::string __str__();) \
145 };
146 
147 #define SIMPLE_EXCEPTION_DFLT_INSTANCE(exception_name, description_value, \
148  default_instance_value) \
149 SWIGOUT(%rename(exception_name) HOM_ ## exception_name;) \
150 class HOM_API HOM_ ## exception_name : public HOM_Error \
151 { \
152 public: \
153  HOM_ ## exception_name(const char* instance_message = "") \
154  : HOM_Error(instance_message) \
155  {} \
156  HOM_Error* clone() override { return new HOM_ ## exception_name(*this); } \
157  std::string exceptionTypeName() override { return #exception_name; } \
158  std::string description() override { return description_value; } \
159  std::string instanceMessage() override \
160  { \
161  std::string instance_msg = HOM_Error::instanceMessage(); \
162  if (!instance_msg.size()) instance_msg = default_instance_value; \
163  return instance_msg; \
164  } \
165  SWIGOUT(std::string __repr__();) \
166  SWIGOUT(std::string __str__();) \
167 };
168 
169 SIMPLE_EXCEPTION(NotAvailable,
170  "Not available in this context")
171 SIMPLE_EXCEPTION(ObjectWasDeleted,
172  "Attempt to access an object that no longer exists in Houdini")
173 SIMPLE_EXCEPTION(InvalidInput,
174  "Invalid input")
175 SIMPLE_EXCEPTION(InvalidOutput,
176  "Invalid output")
177 SIMPLE_EXCEPTION(InvalidSize,
178  "Invalid size")
179 INTERNAL_EXCEPTION(TypeError,
180  "Invalid type")
181 INTERNAL_EXCEPTION(ValueError,
182  "Invalid value")
183 SIMPLE_EXCEPTION(OperationFailed,
184  "The attempted operation failed")
185 SIMPLE_EXCEPTION(InvalidNodeType,
186  "The node type is invalid")
187 SIMPLE_EXCEPTION(InitScriptFailed,
188  "Node initialization script failed")
189 SIMPLE_EXCEPTION(MatchDefinitionError,
190  "Failed to match node type definition")
191 SIMPLE_EXCEPTION_DFLT_INSTANCE(PermissionError, "",
192  "Failed to modify node or parameter because of a permission "
193  "error. Possible causes include locked assets, takes, "
194  "product permissions or user specified permissions")
195 SIMPLE_EXCEPTION(GeometryPermissionError,
196  "Geometry is read-only")
197 SIMPLE_EXCEPTION(KeyframeValueNotSet,
198  "This keyframe value is not set")
199 SIMPLE_EXCEPTION(OperationInterrupted,
200  "The requested operation was interrupted")
201 SIMPLE_EXCEPTION(LoadWarning,
202  "Warnings were generated during load")
203 SIMPLE_EXCEPTION(NodeError,
204  "Error generated by Python node")
205 SIMPLE_EXCEPTION(NodeWarning,
206  "Warning generated by Python node")
207 SIMPLE_EXCEPTION(NameConflict,
208  "Name conflict was detected")
209 SIMPLE_EXCEPTION(TypeConflict,
210  "Type conflict was detected")
211 SIMPLE_EXCEPTION(StateNotRegistered,
212  "Attempt to unregister a non-registered state")
213 SIMPLE_EXCEPTION(HandleNotRegistered,
214  "Attempt to unregister a non-registered handle")
215 
216 DERIVED_EXCEPTION(InvalidGeometry, OperationFailed,
217  "The underlying geometry is not valid. Possibly caused "
218  "by the source SOP Node failing to cook since the python "
219  "geometry was assigned.")
220 
221 #endif
virtual std::string exceptionTypeName()
Definition: HOM_Errors.h:58
std::string __str__()
Definition: HOM_Errors.h:72
#define INTERNAL_EXCEPTION(exception_name, description_value)
Definition: HOM_Errors.h:112
Definition: ImfName.h:30
#define SIMPLE_EXCEPTION(exception_name, description_value)
Definition: HOM_Errors.h:97
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:191
Definition: Node.h:52
GLsizei const GLchar *const * string
Definition: glcorearb.h:814
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:56
GLboolean GLboolean GLboolean GLboolean a
Definition: glcorearb.h:1222
**But if you need a result
Definition: thread.h:613
#define DERIVED_EXCEPTION(exception_name, base_exception, description_value)
Definition: HOM_Errors.h:132
void read(T &in, bool &v)
Definition: ImfXdr.h:502
< returns > If no error
Definition: snippets.dox:2
#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
GLsizei GLsizei GLchar * source
Definition: glcorearb.h:803
virtual std::string instanceMessage()
Definition: HOM_Errors.h:62
std::string __repr__()
Definition: HOM_Errors.h:64
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:191
GLsizeiptr size
Definition: glcorearb.h:664
Error
Definition: oidn.hpp:319
OIIO_UTIL_API bool rename(string_view from, string_view to, std::string &err)
virtual ~HOM_Error()
Definition: HOM_Errors.h:53
#define SIMPLE_EXCEPTION_DFLT_INSTANCE(exception_name, description_value, default_instance_value)
Definition: HOM_Errors.h:147
Definition: core.h:1131
HOM_SystemExit(int exit_code)
Definition: HOM_Errors.h:25
type
Definition: core.h:1059
virtual std::string description()
Definition: HOM_Errors.h:60