-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_error.c
50 lines (42 loc) · 1.25 KB
/
test_error.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include "@/public/error.h"
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
u7_error fn_ok(void) { return u7_ok(); }
u7_error fn_err(void) {
U7_RETURN_IF_ERROR(
u7_errorf(u7_errno_category(), EINVAL, "%s", "Hello, World!"));
return u7_ok();
}
u7_error gn_err(void) {
return u7_errorf_with_cause(u7_errno_category(), EINVAL, fn_err(), "%s",
"foo.bar");
}
int main(void) {
u7_error error;
if ((error = fn_ok()).error_code) {
fprintf(stderr, "%" U7_ERROR_FMT "\n", U7_ERROR_FMT_PARAMS(error));
u7_error_release(error);
return -1;
} else {
fprintf(stderr, "%" U7_ERROR_FMT "\n", U7_ERROR_FMT_PARAMS(error));
u7_error_release(error);
}
if ((error = fn_err()).error_code) {
fprintf(stderr, "%" U7_ERROR_FMT "\n", U7_ERROR_FMT_PARAMS(error));
u7_error_release(error);
} else {
fprintf(stderr, "%" U7_ERROR_FMT "\n", U7_ERROR_FMT_PARAMS(error));
u7_error_release(error);
return -1;
}
if ((error = gn_err()).error_code) {
fprintf(stderr, "%" U7_ERROR_FMT "\n", U7_ERROR_FMT_PARAMS(error));
u7_error_release(error);
} else {
fprintf(stderr, "%" U7_ERROR_FMT "\n", U7_ERROR_FMT_PARAMS(error));
u7_error_release(error);
return -1;
}
return 0;
}