@@ -152,6 +152,41 @@ def b(x: str | bytes) -> bytes:
152
152
### Exception Classes ###
153
153
154
154
155
+ class CXError (Exception ):
156
+ '''Represents C error of type enum CXErrorCode.'''
157
+
158
+ # A generic error code, no further details are available.
159
+ #
160
+ # Errors of this kind can get their own specific error codes in future
161
+ # libclang versions.
162
+ ERROR_FAILURE = 1
163
+
164
+ # libclang crashed while performing the requested operation.
165
+ ERROR_CRASHED = 2
166
+
167
+ # The function detected that the arguments violate the function
168
+ # contract.
169
+ ERROR_INVALID_ARGUMENTS = 3
170
+
171
+ # An AST deserialization error has occurred.
172
+ ERROR_AST_READ_ERROR = 4
173
+
174
+ error_code : int
175
+
176
+ def __init__ (self , enumeration : int , message : str ):
177
+ assert isinstance (enumeration , int )
178
+
179
+ if enumeration < 1 or enumeration > 4 :
180
+ raise Exception (
181
+ "Encountered undefined CXError "
182
+ "constant: %d. Please file a bug to have this "
183
+ "value supported." % enumeration
184
+ )
185
+
186
+ self .error_code = enumeration
187
+ Exception .__init__ (self , "Error %d: %s" % (enumeration , message ))
188
+
189
+
155
190
class TranslationUnitLoadError (Exception ):
156
191
"""Represents an error that occurred when loading a TranslationUnit.
157
192
@@ -3263,9 +3298,11 @@ def reparse(self, unsaved_files=None, options=0):
3263
3298
unsaved_files = []
3264
3299
3265
3300
unsaved_files_array = self .process_unsaved_files (unsaved_files )
3266
- ptr = conf .lib .clang_reparseTranslationUnit (
3301
+ result = conf .lib .clang_reparseTranslationUnit (
3267
3302
self , len (unsaved_files ), unsaved_files_array , options
3268
3303
)
3304
+ if result != 0 :
3305
+ raise CXError (result , 'Error reparsing TranslationUnit.' )
3269
3306
3270
3307
def save (self , filename ):
3271
3308
"""Saves the TranslationUnit to a file.
0 commit comments