From e81c5e26901d0b03b1455bff35f2dd58a8e7af9c Mon Sep 17 00:00:00 2001 From: Madeorsk Date: Sat, 15 Jul 2023 14:42:33 +0200 Subject: [PATCH] Add a function to try to get a result or throw the error if there is one. --- include/ksr/errors.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/include/ksr/errors.h b/include/ksr/errors.h index 8a01016..2ac291d 100644 --- a/include/ksr/errors.h +++ b/include/ksr/errors.h @@ -132,6 +132,16 @@ typedef struct { if (!ksresult_check(__ksresult_cache__)) return __ksresult_cache__; \ varname = ((result_type) __ksresult_cache__.result); \ } +/** + * Try to get a result and put it in the variable called varname. + * You must specify the type of the result you want to get. + * If there is an error, it is thrown directly. You cannot use this function if your function does not return a ksrerror. + */ +#define ksresult_get_throwerr(varname, result_type, _result) NULL; { \ + ksresult __ksresult_cache__ = (_result); \ + if (!ksresult_check(__ksresult_cache__)) return __ksresult_cache__.error; \ + varname = ((result_type) __ksresult_cache__.result); \ +} /** * Try to get a result while ignoring the error if there is one. * You must specify the type of the result you want to get.