Skip to main content
spelling mistake
Source Link
dbmikus
  • 145
  • 6

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:

  1. the state changes in otherContract made by otherContract.firstMethod will not be reverted
  2. the state changes in otherContract made by otherContract.secondMethod will be reverted

From this question it appears that the 10 sent to othreContractotherContract will be refunded but any used gas will not be refunded.

Are all of the above correct? Anything incorrect?

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:

  1. the state changes in otherContract made by otherContract.firstMethod will not be reverted
  2. the state changes in otherContract made by otherContract.secondMethod will be reverted

From this question it appears that the 10 sent to othreContract will be refunded but any used gas will not be refunded.

Are all of the above correct? Anything incorrect?

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:

  1. the state changes in otherContract made by otherContract.firstMethod will not be reverted
  2. the state changes in otherContract made by otherContract.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?

Source Link
dbmikus
  • 145
  • 6

Exact behavior of state revert in `try/catch`

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:

  1. the state changes in otherContract made by otherContract.firstMethod will not be reverted
  2. the state changes in otherContract made by otherContract.secondMethod will be reverted

From this question it appears that the 10 sent to othreContract will be refunded but any used gas will not be refunded.

Are all of the above correct? Anything incorrect?