Skip to content

Instantly share code, notes, and snippets.

@prashantvc
Created December 19, 2013 16:26
Show Gist options
  • Save prashantvc/8042038 to your computer and use it in GitHub Desktop.
Save prashantvc/8042038 to your computer and use it in GitHub Desktop.
using System;
using Android.App;
using Android.Widget;
using Android.OS;
using Java.Lang;
namespace UnhandledCrash
{
[Activity (Label = "UnhandledCrash", MainLauncher = true)]
public class MainActivity : Activity
{
private ImageView image;
private const string TAG = "UnhandledCrash";
protected override void OnCreate (Bundle bundle)
{
base.OnCreate (bundle);
Thread.DefaultUncaughtExceptionHandler = new ExceptionHandler ();
// Set our view from the "main" layout resource
SetContentView (Resource.Layout.Main);
// prepare the crash
image = FindViewById<ImageView> (Resource.Id.myImage);
// Get our button from the layout resource,
// and attach an event to it
Button button = FindViewById<Button> (Resource.Id.myButton);
button.Click += delegate {
// cause a crash by using wrong layoutParams. the problem is that the crash seems not to be catched
image.LayoutParameters = new RelativeLayout.LayoutParams (300, 300);
};
}
}
public class ExceptionHandler : Java.Lang.Object, Thread.IUncaughtExceptionHandler
{
public void UncaughtException (Thread thread, Throwable ex)
{
Console.WriteLine (ex.ToString ());
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment