I want to develop a basic app for Android which must crash randomly to test 'crittercism' tool. What must i do to make an app crash?
Thanks.
I want to develop a basic app for Android which must crash randomly to test 'crittercism' tool. What must i do to make an app crash?
Thanks.
There are quite few questions about this on SO, and most of the answers suggest creative ways to do something illegal that triggers the exception. I believe they are not practical, especially if you want to test for different types of exceptions.
The right way to do it is:
throw new RuntimeException("some message");
or for specific ones:
throw new IllegalStateException("some message");
throw new NullPointerException("some message");
throw new ArrayIndexOutOfBoundsException("some message");
throw new ClassCastException("some message");
...
See: https://developer.android.com/reference/java/lang/RuntimeException.html
You can do the same with any checked type of exceptions to test your exception handling (try/catch).
Set something to null and try to use it, like: