```python class A: def B(self): return 5 stub = sinon.stub(A, 'B').onFirstCall().throws(BaseException('Hello World')).onSecondCall().returns(42) stub() # error stub() stub() stub.restore() ```