Wrap callback to handle exceptions