Easy solution: He should just run a static analyzer on the code first to see if it will terminate before he executes it.
This is provably impossible in the general case [1] and almost impossible in his specific case. It's extremely difficult to know if/when a program will terminate using just static analysis. Edit: Why the down vote? [1] http://en.wikipedia.org/wiki/Halting_problem
The down votes are because it was a joke, punctuated by the "easy solution" preface. The author is almost certainly aware of the halting problem.