xref: /llvm-project/llvm/include/llvm-c/Error.h (revision 45ef0d492f7b61613d0833fbf7eafdd41e137139)
1 /*===------- llvm-c/Error.h - llvm::Error class C Interface -------*- C -*-===*\
2 |*                                                                            *|
3 |* Part of the LLVM Project, under the Apache License v2.0 with LLVM          *|
4 |* Exceptions.                                                                *|
5 |* See https://llvm.org/LICENSE.txt for license information.                  *|
6 |* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception                    *|
7 |*                                                                            *|
8 |*===----------------------------------------------------------------------===*|
9 |*                                                                            *|
10 |* This file defines the C interface to LLVM's Error class.                   *|
11 |*                                                                            *|
12 \*===----------------------------------------------------------------------===*/
13 
14 #ifndef LLVM_C_ERROR_H
15 #define LLVM_C_ERROR_H
16 
17 #include "llvm-c/ExternC.h"
18 
19 LLVM_C_EXTERN_C_BEGIN
20 
21 /**
22  * @defgroup LLVMCError Error Handling
23  * @ingroup LLVMC
24  *
25  * @{
26  */
27 
28 #define LLVMErrorSuccess 0
29 
30 /**
31  * Opaque reference to an error instance. Null serves as the 'success' value.
32  */
33 typedef struct LLVMOpaqueError *LLVMErrorRef;
34 
35 /**
36  * Error type identifier.
37  */
38 typedef const void *LLVMErrorTypeId;
39 
40 /**
41  * Returns the type id for the given error instance, which must be a failure
42  * value (i.e. non-null).
43  */
44 LLVMErrorTypeId LLVMGetErrorTypeId(LLVMErrorRef Err);
45 
46 /**
47  * Dispose of the given error without handling it. This operation consumes the
48  * error, and the given LLVMErrorRef value is not usable once this call returns.
49  * Note: This method *only* needs to be called if the error is not being passed
50  * to some other consuming operation, e.g. LLVMGetErrorMessage.
51  */
52 void LLVMConsumeError(LLVMErrorRef Err);
53 
54 /**
55  * Report a fatal error if Err is a failure value.
56  *
57  * This function can be used to wrap calls to fallible functions ONLY when it is
58  * known that the Error will always be a success value.
59  */
60 void LLVMCantFail(LLVMErrorRef Err);
61 
62 /**
63  * Returns the given string's error message. This operation consumes the error,
64  * and the given LLVMErrorRef value is not usable once this call returns.
65  * The caller is responsible for disposing of the string by calling
66  * LLVMDisposeErrorMessage.
67  */
68 char *LLVMGetErrorMessage(LLVMErrorRef Err);
69 
70 /**
71  * Dispose of the given error message.
72  */
73 void LLVMDisposeErrorMessage(char *ErrMsg);
74 
75 /**
76  * Returns the type id for llvm StringError.
77  */
78 LLVMErrorTypeId LLVMGetStringErrorTypeId(void);
79 
80 /**
81  * Create a StringError.
82  */
83 LLVMErrorRef LLVMCreateStringError(const char *ErrMsg);
84 
85 /**
86  * @}
87  */
88 
89 LLVM_C_EXTERN_C_END
90 
91 #endif
92