3

I'm trying to compile a contract in the solidity browser compiler and get this error:

Untitled:19:9: Error: Expected primary expression.
}
^

Is this due to the throw; statement?

contract user {

    address public owner;

    function user(){
        owner = msg.sender;
        }

    function kill(){
        suicide(owner);
    }

    modifier onlyOwner{
        if (msg.sender != owner){
            throw;
        }else{
            -
        }
    }
}
1

Here's your modified code:

pragma solidity ^0.4.0;

contract user {

    address public owner;

    function user() {
        owner = msg.sender;
    }

    function kill() {
        suicide(owner);
    }

    modifier onlyOwner {
        if (msg.sender != owner) {
            throw;
        } else {
            _;
        }
    }
}

The only problem with your code is that I had to replace your - with a _;. See Are underscores `_` in modifiers code or are they just meant to look cool? for more information on the _ modifiers.

Your modified code then compiles perfectly in the Solidity realtime compiler and runtime:

enter image description here

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.