Possible Duplicate:
Exception handling in R
I use glm.nb function to fit an NB model, but sometimes the program gives an error:
Error in while ((it <- it + 1) < limit && abs(del) > eps) { : 
  missing value where TRUE/FALSE needed
The whole program then breaks down. Now I write another function that can address such convergence issue (it's due to extremely large likelihood value; see this post).
My question is: how can I tell R to switch to my own function when the glm.nb function breaks down? 
I was told to look for the error message in the source code of glm.nb and then modify that part. However, I didn't find such codes explicitly, and wonder if there is an easier way in R to jump out of a breaking-down function and switching to another function by some if-else statements? 
 
    