Skip to content

Propagate Error subclasses unchanged instead of indiscriminately wrapping in RuntimeException #178

Description

@jamxia155

Various locations in the code base currently catch all exceptions and throw RuntimeException, e.g.

} catch (Exception e) {
throw new RuntimeException(e.getMessage());

@imotov weighed in on this issue:

I think, for now, this can be replaced with Utils.handleThrowable. More generally, though, I don't think this is a great pattern. We shouldn't indiscriminately wrap everything in a RuntimeException, as that prevents applications using this library from handling serious conditions such as OutOfMemoryError or AssertionError appropriately. In general, it's better to propagate Error subclasses unchanged and only wrap exceptions that are actually intended to be converted into unchecked exceptions.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions