2021-09-05 13:32:15 +02:00
|
|
|
/*
|
|
|
|
* 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.
|
2021-11-08 00:51:39 +01:00
|
|
|
// It's designed with AK::Result and AK::Error in mind.
|
2021-09-05 13:32:15 +02:00
|
|
|
|
2022-01-15 23:33:27 +02:00
|
|
|
#define TRY(expression) \
|
|
|
|
({ \
|
|
|
|
auto _temporary_result = (expression); \
|
|
|
|
if (_temporary_result.is_error()) [[unlikely]] \
|
|
|
|
return _temporary_result.release_error(); \
|
|
|
|
_temporary_result.release_value(); \
|
2021-09-05 13:32:15 +02:00
|
|
|
})
|
2021-11-10 11:54:54 +01:00
|
|
|
|
|
|
|
#define MUST(expression) \
|
|
|
|
({ \
|
|
|
|
auto _temporary_result = (expression); \
|
|
|
|
VERIFY(!_temporary_result.is_error()); \
|
|
|
|
_temporary_result.release_value(); \
|
|
|
|
})
|