mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 15:40:19 +00:00
cbdd069279
"result" is a tad bit too generic to provide a clash-free experience - we found instances in LibJS where this breaks already. Essentially this doesn't work: auto foo = TRY(bar(result)); Because it expands to the following within the TRY() scope: { auto result = bar(result); ... } And that of course fails: error: use of ‘result’ before deduction of ‘auto’ The simple solution here is to use a name that is much less likely to clash with anything used in the expression ("_temporary_result"). :^)
18 lines
613 B
C
18 lines
613 B
C
/*
|
|
* 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 _temporary_result = (expression); \
|
|
if (_temporary_result.is_error()) \
|
|
return _temporary_result.release_error(); \
|
|
_temporary_result.release_value(); \
|
|
})
|