I just want to crash an Android application and display the “Dialog of Death” (Force Close Dialog) using
Exception in Android. Is it possible? How is it done?
What you want is a
RuntimeException, since the compiler will otherwise force you to move your code inside a try-catch block.
throw new RuntimeException("Crash!");
I think you are looking for uncaughtExceptionHandler.
Here is a very good example,
use this code in your Activity to register a Uncaught Exception Handler,
try to put any erroneous statement in try block, there are so many exceptions available like
arrayindexoutofbounds and so on then do what you want to do in catch.
And for displaying forceclose dialog, you need not to do something when you don’t catch it by default the force close dialog appears.
And why to catch the exception when you want to crash the app?