From 1826579f80f7bb7d274765064c4d69f9232f6dd6 Mon Sep 17 00:00:00 2001 From: Denton Liu Date: Wed, 17 Aug 2016 12:07:03 -0400 Subject: Add documentation about throwing --- docs/control-structures.rst | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/docs/control-structures.rst b/docs/control-structures.rst index 5b78d099..ecbf4d12 100644 --- a/docs/control-structures.rst +++ b/docs/control-structures.rst @@ -299,11 +299,12 @@ In the following example, we show how ``throw`` can be used to easily revert an } } -Currently, there are three situations, where exceptions happen automatically in Solidity: +Currently, there are four situations, where exceptions happen automatically in Solidity: -1. If you access an array beyond its length (i.e. ``x[i]`` where ``i >= x.length``) +1. If you access an array beyond its length (i.e. ``x[i]`` where ``i >= x.length``). 2. If a function called via a message call does not finish properly (i.e. it runs out of gas or throws an exception itself). 3. If a non-existent function on a library is called or Ether is sent to a library. +4. If you divide or modulo by zero (e.g. ``5 / 0`` or ``23 % 0``). 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. -- cgit From c2cfc819a20292f6085a8583336ed88fd70cb98b Mon Sep 17 00:00:00 2001 From: Denton Liu Date: Wed, 17 Aug 2016 14:13:53 -0400 Subject: Document throwing on calling empty code --- docs/control-structures.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/control-structures.rst b/docs/control-structures.rst index ecbf4d12..f4991520 100644 --- a/docs/control-structures.rst +++ b/docs/control-structures.rst @@ -299,12 +299,13 @@ In the following example, we show how ``throw`` can be used to easily revert an } } -Currently, there are four situations, where exceptions happen automatically in Solidity: +Currently, there are five situations, where exceptions happen automatically in Solidity: 1. If you access an array beyond its length (i.e. ``x[i]`` where ``i >= x.length``). 2. If a function called via a message call does not finish properly (i.e. it runs out of gas or throws an exception itself). 3. If a non-existent function on a library is called or Ether is sent to a library. 4. If you divide or modulo by zero (e.g. ``5 / 0`` or ``23 % 0``). +5. If you perform an external function call targeting a contract that contains no code. 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. -- cgit From bbe7c493adaf7b1d37310ad3d18e2a716f3b6713 Mon Sep 17 00:00:00 2001 From: Denton Liu Date: Thu, 18 Aug 2016 12:47:41 -0400 Subject: Document throwing on contract-creation fail --- docs/control-structures.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/control-structures.rst b/docs/control-structures.rst index f4991520..73b0131f 100644 --- a/docs/control-structures.rst +++ b/docs/control-structures.rst @@ -299,13 +299,14 @@ In the following example, we show how ``throw`` can be used to easily revert an } } -Currently, there are five situations, where exceptions happen automatically in Solidity: +Currently, there are six situations, where exceptions happen automatically in Solidity: 1. If you access an array beyond its length (i.e. ``x[i]`` where ``i >= x.length``). 2. If a function called via a message call does not finish properly (i.e. it runs out of gas or throws an exception itself). 3. If a non-existent function on a library is called or Ether is sent to a library. 4. If you divide or modulo by zero (e.g. ``5 / 0`` or ``23 % 0``). 5. If you perform an external function call targeting a contract that contains no code. +6. If a contract-creation call using the ``new`` keyword fails. 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. -- cgit