aboutsummaryrefslogtreecommitdiffstats
path: root/docs
diff options
context:
space:
mode:
authorYoichi Hirai <i@yoichihirai.com>2017-07-26 22:45:37 +0800
committerGitHub <noreply@github.com>2017-07-26 22:45:37 +0800
commit092c2815e5cb1cdc3ecd30325a67e55e92fe2f49 (patch)
tree82894ca157e4678a9704a4e8c369d50fec707135 /docs
parent43002b7bb8973e02919f23dcea099cb9877e9579 (diff)
parent9c676e796c8ad1b366bc30ef29bfb177974d16d6 (diff)
downloaddexon-solidity-092c2815e5cb1cdc3ecd30325a67e55e92fe2f49.tar.gz
dexon-solidity-092c2815e5cb1cdc3ecd30325a67e55e92fe2f49.tar.zst
dexon-solidity-092c2815e5cb1cdc3ecd30325a67e55e92fe2f49.zip
Merge pull request #2631 from maurelian/maurelian_patch1
Clarify require and assert usage
Diffstat (limited to 'docs')
-rw-r--r--docs/control-structures.rst10
1 files changed, 4 insertions, 6 deletions
diff --git a/docs/control-structures.rst b/docs/control-structures.rst
index 128e6fae..a2fae0b3 100644
--- a/docs/control-structures.rst
+++ b/docs/control-structures.rst
@@ -381,13 +381,11 @@ Error handling: Assert, Require, Revert and Exceptions
Solidity uses state-reverting exceptions to handle errors. Such an exception will undo all changes made to the
state in the current call (and all its sub-calls) and also flag an error to the caller.
The convenience functions ``assert`` and ``require`` can be used to check for conditions and throw an exception
-if the condition is not met. The difference between the two is that ``assert`` should only be used for internal errors
-and ``require`` should be used to check external conditions (invalid inputs or errors in external components).
-The idea behind that is that analysis tools can check your contract and try to come up with situations and
-series of function calls that will reach a failing assertion. If this is possible, this means there is a bug
-in your contract you should fix.
+if the condition is not met. The ``assert`` function should only be used to test for internal errors, and to check invariants.
+The ``require`` function should be used to ensure valid conditions, such as inputs, or contract state variables are met, or to validate return values from calls to external contracts.
+If used properly, analysis tools can evaluate your contract to identify the conditions and function calls which will reach a failing ``assert``. Properly functioning code should never it is reach a failing assert statement, if this happens there is a bug in your contract which you should fix.
-There are two other ways to trigger execptions: The ``revert`` function can be used to flag an error and
+There are two other ways to trigger exceptions: The ``revert`` function can be used to flag an error and
revert the current call. In the future it might be possible to also include details about the error
in a call to ``revert``. The ``throw`` keyword can also be used as an alternative to ``revert()``.