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;)
45 SWIGOUT(%rename(Error) HOM_Error;)
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  {
74  std::string result;
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  virtual HOM_Error* clone() { return new HOM_ ## exception_name(*this); } \
106  virtual std::string exceptionTypeName() { return #exception_name; } \
107  virtual std::string description() { return description_value; } \
108  SWIGOUT(std::string __repr__();) \
109  SWIGOUT(std::string __str__();) \
110 };
111 
112 #define SIMPLE_EXCEPTION_DFLT_INSTANCE(exception_name, description_value, \
113  default_instance_value) \
114 SWIGOUT(%rename(exception_name) HOM_ ## exception_name;) \
115 class HOM_API HOM_ ## exception_name : public HOM_Error \
116 { \
117 public: \
118  HOM_ ## exception_name(const char* instance_message = "") \
119  : HOM_Error(instance_message) \
120  {} \
121  virtual HOM_Error* clone() { return new HOM_ ## exception_name(*this); } \
122  virtual std::string exceptionTypeName() { return #exception_name; } \
123  virtual std::string description() { return description_value; } \
124  virtual std::string instanceMessage() \
125  { \
126  std::string instance_msg = HOM_Error::instanceMessage(); \
127  if (!instance_msg.size()) instance_msg = default_instance_value; \
128  return instance_msg; \
129  } \
130  SWIGOUT(std::string __repr__();) \
131  SWIGOUT(std::string __str__();) \
132 };
133 
134 SIMPLE_EXCEPTION(NotAvailable,
135  "Not available in this context")
136 SIMPLE_EXCEPTION(ObjectWasDeleted,
137  "Attempt to access an object that no longer exists in Houdini")
138 SIMPLE_EXCEPTION(InvalidInput,
139  "Invalid input")
140 SIMPLE_EXCEPTION(InvalidSize,
141  "Invalid size")
142 SIMPLE_EXCEPTION(TypeError,
143  "Invalid type")
144 SIMPLE_EXCEPTION(ValueError,
145  "Invalid value")
146 SIMPLE_EXCEPTION(OperationFailed,
147  "The attempted operation failed")
148 SIMPLE_EXCEPTION(InvalidNodeType,
149  "The node type is invalid")
150 SIMPLE_EXCEPTION(InitScriptFailed,
151  "Node initialization script failed")
152 SIMPLE_EXCEPTION(MatchDefinitionError,
153  "Failed to match node type definition")
154 SIMPLE_EXCEPTION_DFLT_INSTANCE(PermissionError, "",
155  "Failed to modify node or parameter because of a permission "
156  "error. Possible causes include locked assets, takes, "
157  "product permissions or user specified permissions")
158 SIMPLE_EXCEPTION(GeometryPermissionError,
159  "Geometry is read-only")
160 SIMPLE_EXCEPTION(KeyframeValueNotSet,
161  "This keyframe value is not set")
162 SIMPLE_EXCEPTION(OperationInterrupted,
163  "The requested operation was interrupted")
164 SIMPLE_EXCEPTION(LoadWarning,
165  "Warnings were generated during load")
166 SIMPLE_EXCEPTION(NodeError,
167  "Error generated by Python node")
168 SIMPLE_EXCEPTION(NodeWarning,
169  "Warning generated by Python node")
170 SIMPLE_EXCEPTION(NameConflict,
171  "Name conflict was detected")
172 
173 #endif
virtual std::string exceptionTypeName()
Definition: HOM_Errors.h:58
std::string __str__()
Definition: HOM_Errors.h:72
Definition: ImfName.h:53
#define SIMPLE_EXCEPTION(exception_name, description_value)
Definition: HOM_Errors.h:97
GLsizei const GLchar *const * string
Definition: glcorearb.h:813
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:1221
void read(T &in, bool &v)
Definition: ImfXdr.h:611
GLsizeiptr size
Definition: glcorearb.h:663
#define HOM_API
Definition: HOM_API.h:13
GLuint GLint GLboolean GLint GLenum access
Definition: glcorearb.h:2221
virtual std::string instanceMessage()
Definition: HOM_Errors.h:62
std::string __repr__()
Definition: HOM_Errors.h:64
GLsizei const GLfloat * value
Definition: glcorearb.h:823
virtual ~HOM_Error()
Definition: HOM_Errors.h:53
#define SIMPLE_EXCEPTION_DFLT_INSTANCE(exception_name, description_value, default_instance_value)
Definition: HOM_Errors.h:112
GLint GLint GLsizei GLint GLenum GLenum type
Definition: glcorearb.h:107
HOM_SystemExit(int exit_code)
Definition: HOM_Errors.h:25
virtual std::string description()
Definition: HOM_Errors.h:60