How do you handle global error states in an Android application?

Instruction: Describe strategies for managing and recovering from application-wide errors or exceptions.

Context: This question explores the candidate's approach to error handling and resilience in Android apps, including logging, user notifications, and recovery mechanisms.

Updated

Official answer

Handle expected failures at a boundary that understands the operation. A repository can distinguish a network outage, expired session, validation failure and unavailable local data; the UI can then show a retry, sign-in action or read-only state without pretending the operation succeeded.

For a global condition such as an expired session, use one owned state transition so multiple failing requests do not open repeated dialogs. Preserve an important draft before navigating and retry only operations whose duplicate effects are understood. Do not automatically repeat a payment or write after a timeout without checking its identity/result.

An uncaught-exception handler runs when a thread is terminating. It is a last-resort diagnostic hook, not a way to resume the failed operation safely. Do not swallow fatal exceptions, relaunch an Activity inside the handler and assume the process is healthy, or create a crash/restart loop. Integrate crash reporting without breaking the existing termination/reporting path; recover durable state on a later normal launch.

Catch specific expected coroutine failures and preserve CancellationException propagation. Log a bounded, redacted operation context and error category, avoiding secrets and unnecessary personal data. Do not promise that support is investigating unless that is actually true.

Test offline and session-expiry states, repeated simultaneous failures, canceled requests and interrupted writes. Track crash-free usage and actionable error categories separately from whether the UI displayed a reassuring message.

Uncaught exception contract, Coroutine execution and cancellation

Related Questions