How to handle random popup

This is the approach I am thinking of, but problem is it will take lots of time to put exception handling for each activity.