Handle exception on updating the ontology state

The added code saves both exceptions and updates the state reliably.