HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
UT_Error.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  * NAME: UT_Error.h (Utility Library, C++)
7  *
8  * COMMENTS:
9  * This class is used to store an error or warning, it is
10  * used in conjunction with a global UT_ErrorManager.
11  *
12  */
13 
14 #ifndef __UT_Error__
15 #define __UT_Error__
16 
17 #include "UT_API.h"
18 #include "UT_String.h"
19 #include "UT_SourceLocation.h"
20 
21 class UT_Color;
22 class UT_StringHolder;
23 class UT_WorkBuffer;
24 
26 {
28  UT_ERROR_MESSAGE, // just for communication (eg "ignoring point normals")
29  UT_ERROR_PROMPT, // something that should catch the user's attention
30  UT_ERROR_WARNING, // something bad happened but continuing is an option
31  UT_ERROR_ABORT, // bad error which meant discontinuing current action
32  UT_ERROR_FATAL, // something bad from which we can't recover
34 };
35 
36 // NOTE:
37 // UT_ERROR_JUST_STRING is meant for convenience for times when you need
38 // to list things, or to use more than one string in an error. eg:
39 // Error: Missing token "{"
40 // ref: Animated Parameter Load
41 
43 {
48  UT_ERROR_OUTSTREAM, // output to stream failed in %s.
49  UT_ERROR_INSTREAM, // input from stream failed in %s.
50  UT_ERROR_EARLY_STREAM_END, // unexpected end of input stream is %s.
51  UT_ERROR_SKIP_PACKET_CLASS, // ignoring unrecog data packet (class) in %s.
52  UT_ERROR_SKIP_PACKET_ID, // ignoring unrecog data packet (id) in %s.
53  UT_ERROR_SKIP_TOKEN, // ignoring unrecog token "%s".
54  UT_ERROR_BAD_TOKEN, // unrecog token "%s". Unable to continue
55  UT_ERROR_MISSING_TOKEN, // missing token "%s".
56  UT_ERROR_BAD_INT, // Invalid integer specification (%s)
57  UT_ERROR_BAD_FLOAT, // Invalid float specification (%s)
58  UT_ERROR_JUST_STRING, // %s -- see note above
59  UT_ERROR_BAD_EXTENSION, // Unknown file extension (%s)
60  UT_ERROR_BAD_CPIO_HEADER, // Bad header in CPIO packet
61  UT_ERROR_BAD_CPIO_CONTENTS, // Bad contents in CPIO packet
62  UT_ERROR_CANT_MKDIR_FILE_EXISTS, // Can't make directory, file exists
63  UT_ERROR_FILE_NOT_WRITEABLE, // Unable to write to file (%s)
64  UT_ERROR_ABORT_BY_USER, // Action aborted by user: %s
65  UT_ERROR_LOW_VIDEO_RAM, // Houdini is running low on graphics VRAM
66  UT_ERROR_DEADLOCK, // Deadlock
67  UT_ERROR_TOO_MANY, // (Too many errors detected)
68  UT_ERROR_HOTKEY_REPORT, // Hotkey pressed; echo command.
69  UT_ERROR_MINIMUM_CPU, // minimum cpu requirement failure
70 };
71 
72 #define UT_CE_EARLY_INPUT_END UT_ERROR_EOF
73 #define UT_CE_PARSE_ERROR UT_ERROR_PARSING
74 #define UT_CE_FILE_ERROR UT_ERROR_FILE_FORMAT
75 
77 {
78 public:
79 
80  // NOTE: A copy of string is stored. String is just an optional
81  // message associated with the error (eg a file name).
82  // "type" is usually a library prefix or it can be either "System"
83  // or "Common".
84  UT_Error(const char *error_type,
85  const int error_code,
86  const char *error_string = nullptr,
88  const UT_SourceLocation *location = nullptr);
89  virtual ~UT_Error();
90 
91  // WARNING! We only copy UT_Error only in cases when it's not subclassed.
92  // If we start copying these via base class pointers, then we're going to
93  // run into slicing bugs.
94  UT_Error(const UT_Error &) = default;
95  UT_Error &operator=(const UT_Error &) = default;
96 
97  virtual int64 getMemoryUsage(bool inclusive) const
98  {
99  int64 mem = inclusive ? sizeof(*this) : 0;
100  mem += myErrorType.getMemoryUsage(false);
101  mem += myErrorString.getMemoryUsage(false);
102  mem += myLocation.getMemoryUsage(false);
103  return mem;
104  }
105 
106  // If you're stringing several errors together, you should set
107  // last to the severity of the last error for which you got the
108  // error message, so that if the severity hasn't changed, we won't
109  // print the "Error/Warning/Message" headers before the message.
110  //
111  // if the use headers flag is off, then the headers (nor spaces in
112  // their place) will be prepended to the message
113  virtual void getErrorMessage(UT_String &error_str,
114  UT_ErrorSeverity last_severity = UT_ERROR_NONE,
115  bool useheaders = true) const;
116  virtual void getErrorFormattedString(
117  UT_WorkBuffer &error_str) const;
118 
119  const UT_String &getErrorType() const { return myErrorType; }
120  UT_ErrorSeverity getSeverity() const { return mySeverity; }
121  bool hasError() const { return mySeverity >= UT_ERROR_ABORT; }
122  int getErrorCode() const { return myErrorCode; }
123  const UT_String &getString() const { return myErrorString; }
124  const UT_SourceLocation &getLocation() const { return myLocation; }
125 
126  void setErrorType(const char *type);
127  void setSeverity(UT_ErrorSeverity);
128  void setErrorString(const char *string);
129  void setErrorCode(int code);
130  void setErrorLocation(const UT_SourceLocation &loc);
131 
132  // getFileString will open the file specified in the filename parameter
133  // and search for the entry with the given error_code. The entry is
134  // placed in the buffer.
135  //
136  // The format of the file is:
137  // # comments
138  // <error_code><single character (non digit)><error message>
139  //
140  // in other words, an error code (string of digits)
141  // a character (typically a tab)
142  // and a newline terminated string
143  // eg:
144  // 145 Generic Error Message.
145  //
146  // Note: You might have a %s in the message somewhere. And also,
147  // only the first nondigit is ignored. All other chars until
148  // the newline, are significant.
149  // Also, all lines with the same code are appended to each other.
150  //
151  // If the error is not found, 0 is returned.
152  //
153  // Note: These files are cached after reading, you have to restart
154  // Houdini to get them to clear out (or write a clearErrorCache method)
155  static bool getErrorFormat(UT_StringHolder &format,
156  const char *error_file,
157  int error_code);
158  static bool getFileString(UT_String &error_str,
159  const char *error_file,
160  int error_code,
162  UT_ErrorSeverity last_severity,
163  bool useheaders);
164 
165 private:
166  UT_String myErrorType;
167  UT_String myErrorString;
168  UT_ErrorSeverity mySeverity;
169  int myErrorCode;
170  UT_SourceLocation myLocation;
171 };
172 
173 #endif
UT_ErrorSeverity
Definition: UT_Error.h:25
#define UT_API
Definition: UT_API.h:14
const UT_SourceLocation & getLocation() const
Definition: UT_Error.h:124
virtual int64 getMemoryUsage(bool inclusive) const
Definition: UT_Error.h:97
int getErrorCode() const
Definition: UT_Error.h:122
UT_ErrorSeverity getSeverity() const
Definition: UT_Error.h:120
GLint GLint GLsizei GLint GLenum format
Definition: glcorearb.h:108
long long int64
Definition: SYS_Types.h:116
GLint location
Definition: glcorearb.h:805
GLenum GLenum severity
Definition: glcorearb.h:2539
const UT_String & getErrorType() const
Definition: UT_Error.h:119
const UT_String & getString() const
Definition: UT_Error.h:123
UT_CommonErrorCode
Definition: UT_Error.h:42
bool hasError() const
Definition: UT_Error.h:121
type
Definition: core.h:1059