0

With the help of this Post I can write the unhandledException to a file. Now how to modify the default popup message that comes when the app get crashed, Default popup will show saying Unfortunately, App has stopped

I need to add report button along with that. Is there any method in xamarin?

Default message When app get crashed: Default message When app get crashed

Modified popup we get when app gets crashed: Modified popup we get when app gets crashed i wanted to do like this.

Koopakiller
  • 2,838
  • 3
  • 32
  • 47
Anish
  • 75
  • 2
  • 10

1 Answers1

0

You will get the "Unfortunately, App has stopped." popup when you get an unhandled exception.

You need a try-catch around code which can potentially throw an exception.

Example:

public bool CompressBitmap(string path, Bitmap bitmap)
{
    var filestream = new FileStream(path, FileMode.Create);
    bitmap.Compress(Bitmap.CompressFormat.Png, 100, filestream);
}

If you call CompressBitmap and bitmap is null, you will get the "Unfortunately, App has stopped." popup because you are not handling the NullReferenceException. You will need a try-catch:

public bool CompressBitmap(string path, Bitmap bitmap)
{
    try
    {
        var filestream = new FileStream(path, FileMode.Create);
        bitmap.Compress(Bitmap.CompressFormat.Png, 100, filestream);
    }
    catch (Exception e)
    {
        // Show your custom dialog with report button and have access to the Exception message with e.Message, e.Stacktrace, etc.
    }
}
Dennis Schröer
  • 2,392
  • 16
  • 46
  • Yes we have to use try-catch to handle the exception. But there will be some exception occurs which is not because of the code ,it can be because of the handset which we are using may not fully support the application then the application may crash.Like this happened with me, application worked properly on one handset but not on the other – Anish Aug 31 '17 at 07:16
  • But it has to crash at a certain point on the code then, doesn't it? I think you need to find the exact place where it crashes and then add the try-catch at this place. – Dennis Schröer Aug 31 '17 at 10:43