diff options
-rw-r--r-- | AK/Try.h | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/AK/Try.h b/AK/Try.h new file mode 100644 index 0000000000..862fc7dbc5 --- /dev/null +++ b/AK/Try.h @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2021, Andreas Kling <kling@serenityos.org> + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +// NOTE: This macro works with any result type that has the expected APIs. +// It's designed with AK::Result and Kernel::KResult in mind. + +#define TRY(expression) \ + ({ \ + auto result = (expression); \ + if (result.is_error()) \ + return result.release_error(); \ + result.release_value(); \ + }) |