I'm trying to make sure I fully understand the behavior of try/catch
, specifically what state gets reverted when we catch an error. I could not be sure of certain behavior from the v0.8.10 docs. If I have code like:
otherContract.firstMethod()
try otherContract.secondMethod{value: 10, gas: 1000}() {}
catch (bytes memory) {
// some code
}
Let's say that otherContract.firstMethod
and otherContract.secondMethod
both modify state within otherContract
. If we end up in the catch block, am I correct in the following statements:
- the state changes in
otherContract
made byotherContract.firstMethod
will not be reverted - the state changes in
otherContract
made byotherContract.secondMethod
will be reverted
From this question it appears that the 10 sent to otherContract
will be refunded but any used gas will not be refunded.
Are all of the above correct? Anything incorrect?