Catch errors when optimizing database.