I would add here some error checking before close. Maybe it is not possible to save canvas in that moment.