1

Is there a possibility to change a state variable and then throw an error, so that the state is maintained. e.g.:

uint minAmount = 1 ether;
uint state;
function payDeposit() payable {
    if(msg.value < minAmount ) {
        state = 2;
        throw;
    }
    state = 1;
 }

In the example above, the state variable is not set. Is there any way to solve this problem?

1

It is not possible, since throw ensures that there are no side effects of the call remain and all gas is consumed.

  • I belivev you could use one of require(msg.value < minAmount or assert(msg.value < minAmount) ...I forget which of the two will maintain state. – theruss Apr 23 '18 at 19:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.