Ensure ontology state is updated even on exceptions

related to #340