Skip to content

Commit

Permalink
tutorial: explain the use case of rethrow_exception and coroutine::ex…
Browse files Browse the repository at this point in the history
…ception

the provided information would allow developer to make a better choice
between these two options that meets their needs.

Signed-off-by: Kefu Chai <[email protected]>
  • Loading branch information
tchaikov committed Apr 2, 2024
1 parent c176dfb commit 42c26f1
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion doc/tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,13 @@ seastar::future<> exception_handling() {
}
```

In certain cases, exceptions can also be propagated directly, without throwing or rethrowing them. It can be achieved by returning a `coroutine::exception` wrapper, but it unfortunately only works for coroutines which return `future<T>`, not `future<>`, due to the limitations in compilers. In particular, the example above won't compile if the return type is changed to `future<>`.
Both `throw` and `std::rethrow_exception()` involve managing stack unwinding and exception objects, potentially
impacting performance. Additionally, the C++ standard permits `std::rethrow_exception()` to create a copy of the
exception object, introducing further overhead. Fortunately, in certain cases, exceptions can also be propagated
directly, without throwing or rethrowing them. It can be achieved by returning a `coroutine::exception` wrapper.
This approach can be advantageous when aiming to minimize overhead associated with exception handling. But it only
works for coroutines which return `future<T>`, not `future<>`, due to the limitations in compilers. In particular,
the example above won't compile if the return type is changed to `future<>`.

Example:

Expand Down

0 comments on commit 42c26f1

Please sign in to comment.