Handle exceptions correctly inside getState()