Added an intermediate function which, if specified, is called on each error encountered