Well the obvious answer seems to be to not pass 0, but if that is not feasible, and you are ok with the function failing, you can catch the exception and handle it in a way that seems right. The program wont crash then.
This tutorial might help explain deeper what you should do.