Merge pull request #3752 from astrofrog/rc_context_exceptions

BUG : Make sure that initial state gets reset if anything goes wrong in ``rc_context``