Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Code health] Stop catching Throwable #2907

Open
gino-m opened this issue Dec 9, 2024 · 1 comment
Open

[Code health] Stop catching Throwable #2907

gino-m opened this issue Dec 9, 2024 · 1 comment
Labels
type: code health Improvements to readability or robustness of codebase

Comments

@gino-m
Copy link
Collaborator

gino-m commented Dec 9, 2024

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):

The root of the Kotlin exception hierarchy is the Throwable class. It has two direct subclasses, Error and 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 or StackOverflowError.

  • The Exception subclass is used for conditions that you might want to handle. Subtypes of the Exception type, such as the RuntimeException and IOException (Input/Output Exception), deal with exceptional events in applications.

@gino-m gino-m added the type: code health Improvements to readability or robustness of codebase label Dec 9, 2024
@gino-m
Copy link
Collaborator Author

gino-m commented Dec 9, 2024

@scolsen @shobhitagarwal1612 @anandwana001 FYI, apologized if I recommended catching Throwable and may have used error() in the past.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: code health Improvements to readability or robustness of codebase
Projects
Status: No status
Development

No branches or pull requests

1 participant