Burak Dede's Blog

Android Debugging - Java Exception Breakpoints

Lets face it debugging is part of the process while developing mobile applications whether it is an Android app or not. It is really frustrating chasing for hours to find simple increment bug or non-called function after your application reach to this will become more frequent.

I will share you a feature that I have been using for a while which makes change-debug-test part much more effective in my opinion. Here is the usual flow

  • Add new feature
  • Build and sign app to test on device
  • App blows up and now look at what exception or error is
  • Nothing comes out, let’s attach debugger to see what’s going on
  • Wait until to come to that screen or feature

This is the general flow when you face with runtime exception they will be mostly NullPointerException but sometimes those are little trickier. Android Studio have a feature that allows you to add new generic breakpoint to catch Exception based on the filter.

Run -> View Breakpoints -> Add(+) -> Java Exception Breakpoint -> RuntimeException

android debugging exceptions

By doing above steps you are basically saying that hey create new breakpoint as soon as you catch any RuntimeException. After applying that next time your app throw RuntimeException it will be directly created breakpoint and go to that line with a debugger attached and you can inspect all the variables on that spot.

This is, of course, tricky because it will also catch/stop any exception thrown by runtime/framework libraries included but not directly related your code. Beware of that.


powered by TinyLetter