diff options
| author | 2023-02-02 15:32:04 +0000 | |
|---|---|---|
| committer | 2023-02-06 10:47:21 +0000 | |
| commit | b91328aba6c34d0590ee0fd66641e0161c95f056 (patch) | |
| tree | 84a97fbc904a56417f7dbe865bd5e0c8875a87dd /libs/androidfw/ApkParsing.cpp | |
| parent | 02cdf72ad3b162d9c42c52b0ad5ea2d35de594cb (diff) | |
Add `suspendRunCatching` to safely handle exceptions without a coroutine
Handling any `CancellationException` by mistake inside a Coroutine may break structured concurrency, `suspendRunCatching` provides a easy way to handle exceptions without interfering in structured concurrency.
For example:
```kotlin
suspend fun example(context: Context) {
val info = suspendRunCatching { context.getSystemService<SystemUpdateManager>()!!.retrieveSystemUpdateInfo() }
.getOrNull() ?: return // a null return is expected, system update info may not be available.
// Do something with the info, like trigger an update.
}
```
Test: atest SystemUITests:CoroutineResultTest
Fixes: b/267486825
Change-Id: I5a98913d26ea2a9e447a16f9da494ae18c4f92f1
Diffstat (limited to 'libs/androidfw/ApkParsing.cpp')
0 files changed, 0 insertions, 0 deletions