From f1d02432a69b44b6bcf784892c332c9f47a829b3 Mon Sep 17 00:00:00 2001 From: Chris Ward Date: Thu, 15 Nov 2018 12:02:38 +0100 Subject: Move undefined FAQ item --- docs/frequently-asked-questions.rst | 38 ------------------------------------- docs/types.rst | 2 ++ 2 files changed, 2 insertions(+), 38 deletions(-) diff --git a/docs/frequently-asked-questions.rst b/docs/frequently-asked-questions.rst index 8b655b0d..a569a896 100644 --- a/docs/frequently-asked-questions.rst +++ b/docs/frequently-asked-questions.rst @@ -143,44 +143,6 @@ arguments for you. See `ping.sol `_ and `pong.sol `_. -When returning a value of say ``uint`` type, is it possible to return an ``undefined`` or "null"-like value? -============================================================================================================ - -This is not possible, because all types use up the full value range. - -You have the option to ``throw`` on error, which will also revert the whole -transaction, which might be a good idea if you ran into an unexpected -situation. - -If you do not want to throw, you can return a pair:: - - pragma solidity >0.4.23 <0.6.0; - - contract C { - uint[] counters; - - function getCounter(uint index) - public - view - returns (uint counter, bool error) { - if (index >= counters.length) - return (0, true); - else - return (counters[index], false); - } - - function checkCounter(uint index) public view { - (uint counter, bool error) = getCounter(index); - if (error) { - // Handle the error - } else { - // Do something with counter. - require(counter > 7, "Invalid counter value"); - } - } - } - - Are comments included with deployed contracts and do they increase deployment gas? ================================================================================== diff --git a/docs/types.rst b/docs/types.rst index 020cb105..e01e2f77 100644 --- a/docs/types.rst +++ b/docs/types.rst @@ -13,6 +13,8 @@ Solidity provides several elementary types which can be combined to form complex In addition, types can interact with each other in expressions containing operators. For a quick reference of the various operators, see :ref:`order`. +The concept of "undefined" or "null" values do not exist in Solidity. To handle any unexpected values, you should use the :ref:`revert function` to revert the whole transaction. + .. index:: ! value type, ! type;value Value Types -- cgit From bc5d152e860fdefd9792937b46af8e3eabce1dc1 Mon Sep 17 00:00:00 2001 From: chriseth Date: Fri, 23 Nov 2018 09:54:27 +0100 Subject: Update docs/types.rst Co-Authored-By: ChrisChinchilla --- docs/types.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/types.rst b/docs/types.rst index e01e2f77..cf123055 100644 --- a/docs/types.rst +++ b/docs/types.rst @@ -13,7 +13,7 @@ Solidity provides several elementary types which can be combined to form complex In addition, types can interact with each other in expressions containing operators. For a quick reference of the various operators, see :ref:`order`. -The concept of "undefined" or "null" values do not exist in Solidity. To handle any unexpected values, you should use the :ref:`revert function` to revert the whole transaction. +The concept of "undefined" or "null" values do not exist in Solidity. To handle any unexpected values, you should use the :ref:`revert function` to revert the whole transaction, or return a tuple with a second `bool` value denoting success. .. index:: ! value type, ! type;value -- cgit From 9c1bdb74b97ea46c621dca430cd401589f800214 Mon Sep 17 00:00:00 2001 From: Chris Ward Date: Fri, 23 Nov 2018 10:16:30 +0100 Subject: Add default value details --- docs/types.rst | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/docs/types.rst b/docs/types.rst index cf123055..5a0acfbb 100644 --- a/docs/types.rst +++ b/docs/types.rst @@ -13,7 +13,10 @@ Solidity provides several elementary types which can be combined to form complex In addition, types can interact with each other in expressions containing operators. For a quick reference of the various operators, see :ref:`order`. -The concept of "undefined" or "null" values do not exist in Solidity. To handle any unexpected values, you should use the :ref:`revert function` to revert the whole transaction, or return a tuple with a second `bool` value denoting success. +The concept of "undefined" or "null" values do not exist in Solidity, but newly +declared variables always have a :ref:`default value` dependent +on its type. To handle any unexpected values, you should use the :ref:`revert function` to revert the whole transaction, or return a +tuple with a second `bool` value denoting success. .. index:: ! value type, ! type;value -- cgit From f57ef36c0e5fdefcb0893c51d466f6b4bb674797 Mon Sep 17 00:00:00 2001 From: Erik Kundt Date: Fri, 23 Nov 2018 17:16:18 +0100 Subject: Update docs/types.rst Co-Authored-By: ChrisChinchilla --- docs/types.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/types.rst b/docs/types.rst index 5a0acfbb..39238f8f 100644 --- a/docs/types.rst +++ b/docs/types.rst @@ -13,7 +13,7 @@ Solidity provides several elementary types which can be combined to form complex In addition, types can interact with each other in expressions containing operators. For a quick reference of the various operators, see :ref:`order`. -The concept of "undefined" or "null" values do not exist in Solidity, but newly +The concept of "undefined" or "null" values does not exist in Solidity, but newly declared variables always have a :ref:`default value` dependent on its type. To handle any unexpected values, you should use the :ref:`revert function` to revert the whole transaction, or return a tuple with a second `bool` value denoting success. -- cgit