Added the possibility to change the function called in case of error.