You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/control-structures.rst
+20-13Lines changed: 20 additions & 13 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -104,7 +104,7 @@ contract can be called internally.
104
104
External Function Calls
105
105
-----------------------
106
106
107
-
The expressions ``this.g(8);`` and ``c.g(2);`` (where ``g`` is a contract
107
+
The expressions ``this.g(8);`` and ``c.g(2);`` (where ``c`` is a contract
108
108
instance) are also valid function calls, but this time, the function
109
109
will be called "externally", via a message call and not directly via jumps.
110
110
Please note that function calls on ``this`` cannot be used in the constructor, as the
@@ -384,18 +384,23 @@ In the following example, we show how ``throw`` can be used to easily revert an
384
384
385
385
Currently, Solidity automatically generates a runtime exception in the following situations:
386
386
387
-
1. If you access an array at a too large or negative index (i.e. ``x[i]`` where ``i >= x.length`` or ``i < 0``).
388
-
1. If you access a fixed-length ``bytesN`` at a too large or negative index.
389
-
1. If you call a function via a message call but it does not finish properly (i.e. it runs out of gas, has no matching function, or throws an exception itself), except when a low level operation ``call``, ``send``, ``delegatecall`` or ``callcode`` is used. The low level operations never throw exceptions but indicate failures by returning ``false``.
390
-
1. If you create a contract using the ``new`` keyword but the contract creation does not finish properly (see above for the definition of "not finish properly").
391
-
1. If you divide or modulo by zero (e.g. ``5 / 0`` or ``23 % 0``).
392
-
1. If you shift by a negative amount.
393
-
1. If you convert a value too big or negative into an enum type.
394
-
1. If you perform an external function call targeting a contract that contains no code.
395
-
1. If your contract receives Ether via a public function without ``payable`` modifier (including the constructor and the fallback function).
396
-
1. If your contract receives Ether via a public accessor function.
397
-
398
-
Internally, Solidity performs an "invalid jump" when an exception is thrown and thus causes the EVM to revert all changes made to the state. The reason for this is that there is no safe way to continue execution, because an expected effect did not occur. Because we want to retain the atomicity of transactions, the safest thing to do is to revert all changes and make the whole transaction (or at least call) without effect.
387
+
#. If you access an array at a too large or negative index (i.e. ``x[i]`` where ``i >= x.length`` or ``i < 0``).
388
+
#. If you access a fixed-length ``bytesN`` at a too large or negative index.
389
+
#. If you call a function via a message call but it does not finish properly (i.e. it runs out of gas, has no matching function, or throws an exception itself), except when a low level operation ``call``, ``send``, ``delegatecall`` or ``callcode`` is used. The low level operations never throw exceptions but indicate failures by returning ``false``.
390
+
#. If you create a contract using the ``new`` keyword but the contract creation does not finish properly (see above for the definition of "not finish properly").
391
+
#. If you divide or modulo by zero (e.g. ``5 / 0`` or ``23 % 0``).
392
+
#. If you shift by a negative amount.
393
+
#. If you convert a value too big or negative into an enum type.
394
+
#. If you perform an external function call targeting a contract that contains no code.
395
+
#. If your contract receives Ether via a public function without ``payable`` modifier (including the constructor and the fallback function).
396
+
#. If your contract receives Ether via a public accessor function.
397
+
#. If you call a zero-initialized variable of internal function type.
398
+
399
+
Internally, Solidity performs an "invalid jump" when a user-provided exception is thrown. In contrast, it performs an invalid operation
400
+
(instruction ``0xfe``) if a runtime exception is encountered. In both cases, this causes
401
+
the EVM to revert all changes made to the state. The reason for this is that there is no safe way to continue execution, because an expected effect
402
+
did not occur. Because we want to retain the atomicity of transactions, the safest thing to do is to revert all changes and make the whole transaction
403
+
(or at least call) without effect.
399
404
400
405
.. index:: ! assembly, ! asm, ! evmasm
401
406
@@ -627,6 +632,8 @@ The opcodes ``pushi`` and ``jumpdest`` cannot be used directly.
0 commit comments