I did some testing with your sample code and found that finish() would work with uncaughtException() . However, it was silent, so it did not give feedback to the user, and, like you, I could not call Toast or any other visual message window even with getApplicationContext() .
The only way to send any feedback I could get is to use the NotificationManager to send the Notification status bar using getApplicationContext() for Context .
I did not spend much time on this, but, unfortunately, this means that you need to provide a PendingIntent for processing when the user clicks on the notification itself. Doing this with the same Activity can obviously lead to an infinite loop if the Activity for the PendingIntent is the one that throws the unhandled exception.
However, it would be possible to create a basic Activity option with a dialogical theme that would be open and explain the failure.
source share