We're trying to figure out whether to use return or throw in Solidity when a condition fails and we don't assume user maliciousness. Here's the pros and cons we've figured so far:
Why use throw
- Any side effects of the code are reverted
- Some wallets may predict
throwahead of time, warning the user
Why use return
- Less gas is consumed by the unsuspecting user (again, assuming not a malicious call).
- A calling contract may gracefully recover from the failure, unlike with
throw.
Are there any other considerations (or best-practices) we should be aware of?
throwconsumes all gas and I added the clarification. Otherwise, an ether transfer is reverted with either athroworrevert. – eth Jun 11 '17 at 08:11throwdoes rollback the sent ether: https://ethereum.stackexchange.com/questions/2428/does-throw-refund-the-ether-value – eth Jun 23 '17 at 05:39