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.
44 SWIGOUT(%ignore HOM_Error::clone;)
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 // Use DERIVED_EXCEPTION when you wish to add a python exception that inherits
113 // from an existing one. This helps to maintain backward compatiblity for
114 // existing python code that already checks for the base_exception as this will
115 // still be caught in the try/except block whilst allowing newer code to perform
116 // more fine-grained checks.
117 
118 #define DERIVED_EXCEPTION(exception_name, base_exception, description_value) \
119 SWIGOUT(%rename(exception_name) HOM_ ## exception_name;) \
120 class HOM_API HOM_ ## exception_name : public HOM_ ## base_exception \
121 { \
122 public: \
123  HOM_ ## exception_name(const char* instance_message = "") \
124  : HOM_ ## base_exception(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  SWIGOUT(std::string __repr__();) \
130  SWIGOUT(std::string __str__();) \
131 };
132 
133 #define SIMPLE_EXCEPTION_DFLT_INSTANCE(exception_name, description_value, \
134  default_instance_value) \
135 SWIGOUT(%rename(exception_name) HOM_ ## exception_name;) \
136 class HOM_API HOM_ ## exception_name : public HOM_Error \
137 { \
138 public: \
139  HOM_ ## exception_name(const char* instance_message = "") \
140  : HOM_Error(instance_message) \
141  {} \
142  HOM_Error* clone() override { return new HOM_ ## exception_name(*this); } \
143  std::string exceptionTypeName() override { return #exception_name; } \
144  std::string description() override { return description_value; } \
145  std::string instanceMessage() override \
146  { \
147  std::string instance_msg = HOM_Error::instanceMessage(); \
148  if (!instance_msg.size()) instance_msg = default_instance_value; \
149  return instance_msg; \
150  } \
151  SWIGOUT(std::string __repr__();) \
152  SWIGOUT(std::string __str__();) \
153 };
154 
155 SIMPLE_EXCEPTION(NotAvailable,
156  "Not available in this context")
157 SIMPLE_EXCEPTION(ObjectWasDeleted,
158  "Attempt to access an object that no longer exists in Houdini")
159 SIMPLE_EXCEPTION(InvalidInput,
160  "Invalid input")
161 SIMPLE_EXCEPTION(InvalidSize,
162  "Invalid size")
163 SIMPLE_EXCEPTION(TypeError,
164  "Invalid type")
165 SIMPLE_EXCEPTION(ValueError,
166  "Invalid value")
167 SIMPLE_EXCEPTION(OperationFailed,
168  "The attempted operation failed")
169 SIMPLE_EXCEPTION(InvalidNodeType,
170  "The node type is invalid")
171 SIMPLE_EXCEPTION(InitScriptFailed,
172  "Node initialization script failed")
173 SIMPLE_EXCEPTION(MatchDefinitionError,
174  "Failed to match node type definition")
175 SIMPLE_EXCEPTION_DFLT_INSTANCE(PermissionError, "",
176  "Failed to modify node or parameter because of a permission "
177  "error. Possible causes include locked assets, takes, "
178  "product permissions or user specified permissions")
179 SIMPLE_EXCEPTION(GeometryPermissionError,
180  "Geometry is read-only")
181 SIMPLE_EXCEPTION(KeyframeValueNotSet,
182  "This keyframe value is not set")
183 SIMPLE_EXCEPTION(OperationInterrupted,
184  "The requested operation was interrupted")
185 SIMPLE_EXCEPTION(LoadWarning,
186  "Warnings were generated during load")
187 SIMPLE_EXCEPTION(NodeError,
188  "Error generated by Python node")
189 SIMPLE_EXCEPTION(NodeWarning,
190  "Warning generated by Python node")
191 SIMPLE_EXCEPTION(NameConflict,
192  "Name conflict was detected")
193 SIMPLE_EXCEPTION(StateNotRegistered,
194  "Attempt to unregister a non-registered state")
195 SIMPLE_EXCEPTION(HandleNotRegistered,
196  "Attempt to unregister a non-registered handle")
197 
198 DERIVED_EXCEPTION(InvalidGeometry, OperationFailed,
199  "The underlying geometry is not valid. Possibly caused "
200  "by the source SOP Node failing to cook since the python "
201  "geometry was assigned.")
202 
203 #endif
virtual std::string exceptionTypeName()
Definition: HOM_Errors.h:58
std::string __str__()
Definition: HOM_Errors.h:72
Definition: ImfName.h:54
#define SIMPLE_EXCEPTION(exception_name, description_value)
Definition: HOM_Errors.h:97
OIIO_API bool rename(string_view from, string_view to, std::string &err)
GLenum GLenum GLenum input
Definition: glew.h:14162
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
#define DERIVED_EXCEPTION(exception_name, base_exception, description_value)
Definition: HOM_Errors.h:118
void read(T &in, bool &v)
Definition: ImfXdr.h:611
GLuint in
Definition: glew.h:11552
GLsizeiptr size
Definition: glcorearb.h:663
GLuint64EXT * result
Definition: glew.h:14311
GLint GLint GLsizei GLint GLenum GLenum type
Definition: glcorearb.h:107
#define HOM_API
Definition: HOM_API.h:13
GLsizei GLsizei GLchar * source
Definition: glcorearb.h:802
GLboolean GLboolean GLboolean GLboolean a
Definition: glcorearb.h:1221
GLsizei const GLchar *const * string
Definition: glcorearb.h:813
virtual std::string instanceMessage()
Definition: HOM_Errors.h:62
std::string __repr__()
Definition: HOM_Errors.h:64
GLuint GLint GLboolean GLint GLenum access
Definition: glcorearb.h:2221
OIIO_API bool exists(string_view path) noexcept
Error
Definition: oidn.hpp:319
virtual ~HOM_Error()
Definition: HOM_Errors.h:53
#define SIMPLE_EXCEPTION_DFLT_INSTANCE(exception_name, description_value, default_instance_value)
Definition: HOM_Errors.h:133
GLsizei const GLfloat * value
Definition: glcorearb.h:823
HOM_SystemExit(int exit_code)
Definition: HOM_Errors.h:25
virtual std::string description()
Definition: HOM_Errors.h:60