When I debug my Xamarin.Forms app on UWP and an exception occurs, the application breaks on the line that the exception is thrown, showing me the exception details, the call stack, and allows me to inspect local variables. However, on android, every single time an exception occurs, I get this extremely unhelpful error:
The application is in Break Mode
Your app has entered a break state, but there is no code to show because all threads were executing external code (typically system or framework code).
An unhandled exception occurred
There are zero details about the exception. No stack trace. No local variables. Nothing.
(Note to the mods: it's really dumb that I'm not allowed to post a screenshot of this because I haven't been on the forums long enough)
Note, if I follow the exact same steps to reproduce any of these exceptions in UWP, the application breaks correctly on the exception and I am able to see the details. It is only in android that I get this useless page with no information.
I've tried adding unhandled exception handlers in my MainActivity, and added breakpoints, but when an exception occurs, the breakpoints never get hit and I still encounter the same useless error page:
[Activity(Label = "Redacted", Icon = "@drawable/icon", Theme = "@style/MainTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
{
protected override void OnCreate(Bundle bundle)
{
TabLayoutResource = Resource.Layout.Tabbar;
ToolbarResource = Resource.Layout.Toolbar;
base.OnCreate(bundle);
global::Xamarin.Forms.Forms.Init(this, bundle);
global::Xamarin.FormsMaps.Init(this, bundle);
AppDomain.CurrentDomain.UnhandledException += HandleUnhandledException;
AndroidEnvironment.UnhandledExceptionRaiser += HandleAndroidUnhandledException;
LoadApplication(new App());
}
public override void OnRequestPermissionsResult(int requestCode, string[] permissions, Permission[] grantResults)
{
PermissionsImplementation.Current.OnRequestPermissionsResult(requestCode, permissions, grantResults);
}
private static void HandleUnhandledException(object sender, UnhandledExceptionEventArgs args)
{
ErrorHandler.HandleException(args.ExceptionObject as Exception);
}
private static void HandleAndroidUnhandledException(object sender, RaiseThrowableEventArgs args)
{
ErrorHandler.HandleException(args.Exception);
}
}
The following is in my Xamarin.Forms assembly:
public static class ErrorHandler
{
public static void HandleException(Exception e)
{
#if DEBUG
System.Diagnostics.Debugger.Break();
#endif
Application.Current.MainPage.DisplayAlert(e.GetType().Name, e.Message, "OK");
}
}
I've also tried both with an emulated device and with a real device, and the same thing happens either way.
Why am I not seeing useful exception information when debugging on android? Is there something I can do in order to stop seeing this useless "The application is in Break Mode" message?