A wrapper that contains either an instance of T, an exception, or nothing.

Synopsis

Declared in <folly/Try.h>

template<class T>
class Try;

Description

Exceptions are stored as exception_wrapper`s so that the user can minimize rethrows if so desired. To represent success or a captured exception, use `Try<Unit>.

Type Aliases

Name

Description

element_type

The value type for the Try.

Member Functions

Name

Description

emplace

In‐place construct the value in the Try object.

emplaceException

In‐place construct an exception in the Try object.

exception

exception overloads

get

get overloads

hasException

hasException overloads

hasValue

Check whether the Try contains a value.

operator*

Dereference operators

operator‐>

Member access operators

throwIfFailed [deprecated]

Rethrow if the Try contains an exception or is empty.

throwUnlessValue

Rethrow if the Try contains an exception or is empty.

tryGetExceptionObject

tryGetExceptionObject overloads

value

value overloads

value_or

Return the contained value, or a fallback if there is none.

withException

withException overloads

Using Declarations

Specializations

Name

Description

Try<void>

Specialization of Try for the void value type.

Deduction Guides

Name

Description

Try<std::decay_t<T>>

Deduction guide that deduces the value type of a Try from a value.

Non-Member Functions

Name

Description

makeTryWith

Execute a function and capture its result as a Try.

makeTryWithNoUnwrap

Execute a function and capture its result as a Try.

result_to_try

Converts a result<T> to a Try<T>.

tryAssign

Try to move the value/exception from another Try object.

tryEmplace

Try to in‐place construct a new value from the specified arguments.

tryEmplaceWith

Try to in‐place construct a new value from the result of a function.

try_to_result

If t is empty, defaults to returning a UsingUninitializedTry result. Pick your own default via empty_try_with{ { return result<T>{...}; }.

try_to_result

Converts a Try<T> to a result<T>, treating empty as an error.

coro::makeResultTask

Make a Task out of a Try.

fibers::async::awaitTry

Await an async‐annotated functor, capturing its result or exception in a Try.

fibers::async::fromTry

Convert a Try into an Async result, rethrowing any stored exception.

Created with MrDocs