Java – Throwing Exceptions on Purpose (Android with Java)

Throwing Exceptions on Purpose (Android with Java)… here is a solution to the problem.

Throwing Exceptions on Purpose (Android with Java)

Well, maybe it’s because of 4:30 on Friday, but I have a question that I think I’ll regret later.

I

have an android activity that implements java.lang.Thread.UncaughtExceptionHandler, and I want to throw some exceptions in different places (to make sure unexpected exceptions are caught later). I just realized that you can’t just throw exceptions outside of try catch, unfortunately my project doesn’t build and execute obvious exceptions like setting values for uninitialized objects (unfortunately correct).

So what’s the best way to make my Android app crash really get better?

Solution

throw new RuntimeException("This is a crash... aa!!!aaa

You’re lucky, my friend, I did exactly the same thing today and found a way to crash my app. Try using the above code somewhere, such as when you press a button to force a crash. Then just tap on all and Android will ask you to close your app. Crash Fulfillment! This worked for me at least.

Related Problems and Solutions