From 4f48a086b75721f246fa496bcfc07bd2b45bae0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?kleines=20Filmr=C3=B6llchen?= Date: Fri, 14 Jan 2022 01:14:24 +0100 Subject: [PATCH] LibAudio: Add LOADER_TRY to auto-convert Error to LoaderError --- Userland/Libraries/LibAudio/LoaderError.h | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Userland/Libraries/LibAudio/LoaderError.h b/Userland/Libraries/LibAudio/LoaderError.h index cc630fcdb8a..583476c032e 100644 --- a/Userland/Libraries/LibAudio/LoaderError.h +++ b/Userland/Libraries/LibAudio/LoaderError.h @@ -64,3 +64,12 @@ struct LoaderError { }; } + +// Convenience TRY-like macro to convert an Error to a LoaderError +#define LOADER_TRY(expression) \ + ({ \ + auto _temporary_result = (expression); \ + if (_temporary_result.is_error()) \ + return LoaderError(_temporary_result.release_error()); \ + _temporary_result.release_value(); \ + })