mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-29 02:50:26 +00:00
cd49f30bea
This is generally useful so let's move it to AK. Also it seems that we don't need the temporary variable hack anymore, so let's lose that.
25 lines
860 B
C
25 lines
860 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 AK::Error in mind.
|
|
|
|
#define TRY(expression) \
|
|
({ \
|
|
auto _temporary_result = (expression); \
|
|
if (_temporary_result.is_error()) \
|
|
return _temporary_result.release_error(); \
|
|
_temporary_result.release_value(); \
|
|
})
|
|
|
|
#define MUST(expression) \
|
|
({ \
|
|
auto _temporary_result = (expression); \
|
|
VERIFY(!_temporary_result.is_error()); \
|
|
_temporary_result.release_value(); \
|
|
})
|