In this trivial example, both require
and throw
perform the same guard. And according to remix using the 0.4.10 compiler, both functions, when presented with a value <= 10 throw : VM Exception: invalid opcode
.
Other than maybe the readability of the code (require
seems to be more intuitive), what's the benefit of using one over the other?
pragma solidity ^0.4.10;
contract Simple {
uint public value1;
uint public value2;
function setOne(uint v) {
require(v > 10);
value1 = v;
}
function setTwo(uint v) {
if(v <= 10 ) throw;
value2 = v;
}
}