google / google/ground-android

[Code health] Stop catching `Throwable`

Open
#2,907 1 comment 0 reactions 0 assignees View on GitHub
type: code health
Dominant language
Kotlin
Stars
293
Forks
149
Avg merge
1d 16h
Merged PRs (30d)
42

Description

If we need to catch all errors, catch Exception instead.

Also, we should avoid using Kotlin `error()` except for unrecoverable exceptions.

We may also want to avoid using `runCatching`, as it requires us to remember to explicitly the exception type in `fold` or other handler lambdas.

From Kotlin docs ([link](https://kotlinlang.org/docs/exceptions.html#exception-hierarchy)):

> The root of the Kotlin exception hierarchy is the [Throwable](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-throwable/) class. It has two direct subclasses, [Error](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-error/) and [Exception](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-exception/):
>
> * The Error subclass represents serious fundamental problems that an application might not be able to recover from by itself. These are problems that you generally would not attempt to handle, such as [OutOfMemoryError](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-out-of-memory-error/) or StackOverflowError.
>
> * The Exception subclass is used for conditions that you might want to handle. Subtypes of the Exception type, such as the [RuntimeException](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-runtime-exception/) and IOException (Input/Output Exception), deal with exceptional events in applications.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.