Fix issue #586

If a stub throws an exception it should restore the `invoking` flag
to false, so it can be reset without throwing an error.