Solidity: Introduce "require()" and "assert()" into documentation

Created on 12 Apr 2017  路  3Comments  路  Source: ethereum/solidity

The examples in the documentation still contain the pattern

if (!x) throw;

All uses of that pattern should be replaced by

require(x);

or

assert(x);

depending on whether the condition is a condition on inputs or authorization checks or whether it is a check for internal consistency (it might be that the latter is not present in the examples).

Most helpful comment

@wski thanks for taking a look here! As I said, I don't think that anything in the documentation actually will use assert(). require() should be used if you are checking the input or whether a user is allowed to do something or whether the contract is in the correct state to do something. You should use assert for e.g. checking that the state of the contract will never be set to something invalid.

All 3 comments

In what situation is require favored over assert? I can take care of this real quick but want to make sure I understand usage correctly first.

@wski thanks for taking a look here! As I said, I don't think that anything in the documentation actually will use assert(). require() should be used if you are checking the input or whether a user is allowed to do something or whether the contract is in the correct state to do something. You should use assert for e.g. checking that the state of the contract will never be set to something invalid.

I left the bit about exceptions showing throw usage. However, it sounds like this should be removed entirely if the intent is to deprecate throw. (referencing https://github.com/ethereum/solidity/issues/1793)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

chriseth picture chriseth  路  4Comments

dexterchan picture dexterchan  路  4Comments

chriseth picture chriseth  路  3Comments

axic picture axic  路  3Comments

madvas picture madvas  路  3Comments