Remove the use of exceptions in apply functions