aboutsummaryrefslogtreecommitdiffstats
path: root/src/try.h
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2023-04-03 08:51:58 -0400
committerDavid Robillard <d@drobilla.net>2023-04-05 09:45:15 -0400
commitb8638fb5c51bcb4d51c6d13c2ee1e4734dfdd616 (patch)
tree538dc4c909648d45d91a33008b797ba0eccc2de7 /src/try.h
parentf93c3fdd6c7d6ca61bec55d3c1ffae7e7c793913 (diff)
downloadserd-b8638fb5c51bcb4d51c6d13c2ee1e4734dfdd616.tar.gz
serd-b8638fb5c51bcb4d51c6d13c2ee1e4734dfdd616.tar.bz2
serd-b8638fb5c51bcb4d51c6d13c2ee1e4734dfdd616.zip
Improve writer error handling
Diffstat (limited to 'src/try.h')
-rw-r--r--src/try.h21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/try.h b/src/try.h
new file mode 100644
index 00000000..f49ae05f
--- /dev/null
+++ b/src/try.h
@@ -0,0 +1,21 @@
+// Copyright 2011-2023 David Robillard <d@drobilla.net>
+// SPDX-License-Identifier: ISC
+
+#ifndef SERD_SRC_TRY_H
+#define SERD_SRC_TRY_H
+
+#define TRY(st, exp) \
+ do { \
+ if (((st) = (exp))) { \
+ return (st); \
+ } \
+ } while (0)
+
+#define TRY_FAILING(st, exp) \
+ do { \
+ if (((st) = (exp)) > SERD_FAILURE) { \
+ return (st); \
+ } \
+ } while (0)
+
+#endif // SERD_SRC_TRY_H