BillHaggerty
BillHaggerty

Reputation: 6571

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?

Upvotes: 2

Views: 991

Answers (1)

Sphig316
Sphig316

Reputation: 216

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.

Upvotes: 11

Related Questions