Skip to content

Unhandled Android exceptions are swallowed silently, so a failed startup looks like a hang #156

Open

Description

@zhollis21

Found while diagnosing the v0.13.0 blank-launch regression (#154). The bug there was a one-word mistake, but what made it unreadable is separate and outlives that fix: the app caught the exception, said nothing, and kept running with no UI. On the phone it looked like a hang.

This is the complement to #155. That one is about bad builds not shipping; this one is about what the app does when something fails anyway.

Problem

1. The Android handler swallows unhandled exceptions silently

Platforms/Android/MainActivity.cs:50:

Android.Runtime.AndroidEnvironment.UnhandledExceptionRaiser += (sender, args) =>
{
    Log.Error(nameof(MainActivity), $"Unhandled Android exception: {args.Exception}");
    args.Handled = true;
};

Handled = true stops the process dying. That is why v0.13.0 presented as a blank window rather than a crash: ShellContent failed to build the Library tab, this handler marked it handled, and the app carried on with nothing to draw. Sentry recorded the event with mechanism: UnhandledExceptionRaiser, confirming this is the path it took.

A visible crash would have been more useful than what shipped — a crash is unambiguous and gets reported; a blank screen reads as a hang and invites a reinstall.

2. It never reaches the crash-alert path its siblings use

App.xaml.cs:14 and :22 both route to ShowCrashAlert, which shows a dialog with the exception type and message (App.xaml.cs:34-59). The Android raiser does not call it — it only logs. So of the three global handlers, the one that caught this failure is the only one that tells the user nothing.

3. A dialog is the wrong surface for a startup failure anyway

ShowCrashAlert bails when there is no page:

var page = Current?.Windows.FirstOrDefault()?.Page;
if (page is null)
{
    return;
}

For a failure during shell construction, a dialog floating over a blank shell is the best case and returning silently is the likely one. What that situation wants is a full-page "the app could not start" view, not an alert.

The app already has the parts: ErrorStateView, ErrorReportService, and the classified per-page error views with retry and a technical-details toggle.

Options

Not settled — recorded while the context is fresh; pick against the real code at kickoff.

A. Have the Android raiser call ShowCrashAlert, keep Handled = true. Smallest change, makes the failure visible immediately. Still a dialog, so it does nothing when there is no page — exactly the startup case that motivated this.

B. A dedicated startup-failure page. On an unhandled exception with no usable content, replace the window's page with an error view reusing ErrorStateView. Covers the case that actually happened. Needs care: the handler runs after arbitrary failure, so building UI is best-effort and must not throw on its own.

C. Stop swallowing, and let it crash. Drop Handled = true. Most honest signal, feeds Play Console vitals properly, and is the smallest diff. Worse first impression, and it discards whatever recoverability the current behaviour buys for non-fatal Java-side exceptions — which is worth measuring before assuming it buys nothing.

Leaning B for the startup case with A as its fallback path, but C deserves a real hearing: swallowing every Java-side exception is how a corrupt state became invisible in the first place.

Constraint

Whatever runs here executes after an arbitrary unhandled exception, so it has to be defensive — ShowCrashAlert already wraps itself in a bare catch for that reason, and any replacement needs the same discipline. Some failures are out of reach entirely: anything before MAUI initialises, or inside MauiProgram.CreateMauiApp, has no UI to draw into. This can be best-effort, not a guarantee, and the issue should not be written as if it can catch everything.

Sentry reporting must keep working whichever option wins — it is what made #154 diagnosable in minutes.

Related

Activity

  1. added
    bug
    UI/UX
    p2-high
    on Aug 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    UI/UXbugp2-high

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions