Skip to content

2.x: Wrapping onError life cycle violations in a marker exception #5035

Closed
@hvisser

Description

@hvisser

Related to my question in #5009, I've run into more situations where onError() might be called outside of the correct observable lifecycle (as a result of an async operation using a subject for example). David noted in #5009, "RxJava can't distinguish between wanted and unwanted errors that are raised beyond the lifecycle (or cancellation)."

However, because these life cycle errors are raised using the default uncaught error exception, they are very hard to distinguish from "normal" unhandled rx errors by the developer too; they look the same and only after verifying that all errors are handled correctly in the stream you'll know for sure that an error must be related to the life cycle. Because they look and act the same, it's not possible to handle those exception in a different way if required either.

Therefore I'd like to propose to wrap errors that are caused by life cycle violations to be wrapped in an exception like RxLifecycleException to signal that a particular error is caused by a programming mistake related to the life cycle, as opposed to an unhandled exception resulting from the stream.

Wrapping life cycle errors like that would also allow developers to choose how to handle these using the global error handler. For example: crash in debug builds, but warn only in production builds if appropriate.

This would keep the general design of not ignoring errors and would make it easier to identify life cycle related errors.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions