fixed error handling in Trainer::train