5

I'm experimenting with contract CrowdFunder which I found on the net

https://github.com/nemild/learnxinyminutes-docs/blob/solidity/solidity.html.markdown

and I'm getting an error Solidity exception (bad jump) when function payOut() is executed and state enum variable is different than the one which is passed to inState(State.Successful)

enum State {
        Fundraising,
        ExpiredRefundPending,
        Successful,
        ExpiredRefundComplete
    }


   modifier inState(State _state) {
        if (state != _state) throw;
        _
    }

If state == _state then there is no error. Function executes as expected.

function payOut()
    public
    inState(State.Successful)
    {
        if(!fundRecipient.send(this.balance)) {
            throw;
        }

        winnerPaid(fundRecipient);
    }

Is this because inState function is defined to execute throw when the _state !=state. Is this the cause of Solidity exception (bad jump)?

3

The modifier inState(State _state) is basically an assertion insuring that before the actual function runs (represented by the _ in the modifier's code), the current state of the contract is in the state given. It sounds to me like it's operating exactly as it should. It's another way of saying "this function (payOut) should only run if the contracts state is _state.

The _ in the modifiers code represents the code in the function that is being modified. So, if the _ comes after the modifiers test, payOut will only run if the condition is met. If the _ came before the modifiers test, payOut would have run first, and then the modifiers test would run.

In the very old days of raw C programming, this may have been done with a #define macro.

5

"bad jump" is just the way "throw" is modeled, so it is expected behaviour.

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.