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.
}
}