Delete image file only when an exception is caught