I stumbled on this EIP which describes the revert
opcode that looks like it allows you to "throw" more specific errors by passing a memory pointer with the opcode (also described briefly in the docs). Note in the docs that return
and revert
receive the same input format.
So far, I have this function as an example:
function throwError(bytes _error) constant returns (bytes32) {
assembly {
calldatacopy(0xff, 0, calldatasize)
return(add(0xff, 68), 32)
}
}
It works as expected, copying the string passed as function parameter and returning it. However, when I change return
to revert
like this:
function throwError(bytes _error) constant returns (bytes32) {
assembly {
calldatacopy(0xff, 0, calldatasize)
revert(add(0xff, 68), 32)
}
}
All I get back is a normal invalid opcode
error from web3, truffle, and remix when testing with testrpc. I don't see any reason why this wouldn't work; is there something I'm missing here?