Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cause an exception on purpose(Android with java)

Ok, so maybe it is because its four thirty on a Friday, but I have a question I think I will regret later on.

I have an android activity that implements java.lang.Thread.UncaughtExceptionHandler, and I want to throw some exceptions in various places(To make sure an unexpected one would be caught later). I just realized you cant just throw and exception outside a try catch, and unfortunately my project doesn't build and execute with obvious exceptions like setting values for uninitialized objects(Unfortunate right).

So whats the best way I can make my android app crash real good?

like image 210
BillHaggerty Avatar asked Jul 16 '26 08:07

BillHaggerty


1 Answers

throw new RuntimeException("This is a crash... AHHHHH!!!!");

You're lucky my friend, I was doing the exact same thing today and found a way to crash my app. Try using the above code somewhere like when you press a button to force a crash. Then just click all over and Android will ask you to close your app. Crash achieved! That's what worked for me at least.

like image 154
Sphig316 Avatar answered Jul 17 '26 22:07

Sphig316



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!