mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge pull request #13679 from fulldecent/feature-order-of-errors
[Documentation] Set error placement in contract, match example to specified order
This commit is contained in:
commit
50935dbcc5
@ -1058,14 +1058,40 @@ Inside each contract, library or interface, use the following order:
|
|||||||
1. Type declarations
|
1. Type declarations
|
||||||
2. State variables
|
2. State variables
|
||||||
3. Events
|
3. Events
|
||||||
4. Modifiers
|
4. Errors
|
||||||
5. Functions
|
5. Modifiers
|
||||||
|
6. Functions
|
||||||
|
|
||||||
.. note::
|
.. note::
|
||||||
|
|
||||||
It might be clearer to declare types close to their use in events or state
|
It might be clearer to declare types close to their use in events or state
|
||||||
variables.
|
variables.
|
||||||
|
|
||||||
|
Yes:
|
||||||
|
|
||||||
|
.. code-block:: solidity
|
||||||
|
|
||||||
|
// SPDX-License-Identifier: GPL-3.0
|
||||||
|
pragma solidity >=0.8.4 <0.9.0;
|
||||||
|
|
||||||
|
abstract contract Math {
|
||||||
|
error DivideByZero();
|
||||||
|
function divide(int256 numerator, int256 denominator) public virtual returns (uint256);
|
||||||
|
}
|
||||||
|
|
||||||
|
No:
|
||||||
|
|
||||||
|
.. code-block:: solidity
|
||||||
|
|
||||||
|
// SPDX-License-Identifier: GPL-3.0
|
||||||
|
pragma solidity >=0.8.4 <0.9.0;
|
||||||
|
|
||||||
|
abstract contract Math {
|
||||||
|
function divide(int256 numerator, int256 denominator) public virtual returns (uint256);
|
||||||
|
error DivideByZero();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
******************
|
******************
|
||||||
Naming Conventions
|
Naming Conventions
|
||||||
******************
|
******************
|
||||||
@ -1130,15 +1156,15 @@ Yes:
|
|||||||
contract Owned {
|
contract Owned {
|
||||||
address public owner;
|
address public owner;
|
||||||
|
|
||||||
constructor() {
|
|
||||||
owner = msg.sender;
|
|
||||||
}
|
|
||||||
|
|
||||||
modifier onlyOwner {
|
modifier onlyOwner {
|
||||||
require(msg.sender == owner);
|
require(msg.sender == owner);
|
||||||
_;
|
_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
owner = msg.sender;
|
||||||
|
}
|
||||||
|
|
||||||
function transferOwnership(address newOwner) public onlyOwner {
|
function transferOwnership(address newOwner) public onlyOwner {
|
||||||
owner = newOwner;
|
owner = newOwner;
|
||||||
}
|
}
|
||||||
@ -1169,15 +1195,15 @@ No:
|
|||||||
contract owned {
|
contract owned {
|
||||||
address public owner;
|
address public owner;
|
||||||
|
|
||||||
constructor() {
|
|
||||||
owner = msg.sender;
|
|
||||||
}
|
|
||||||
|
|
||||||
modifier onlyOwner {
|
modifier onlyOwner {
|
||||||
require(msg.sender == owner);
|
require(msg.sender == owner);
|
||||||
_;
|
_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
owner = msg.sender;
|
||||||
|
}
|
||||||
|
|
||||||
function transferOwnership(address newOwner) public onlyOwner {
|
function transferOwnership(address newOwner) public onlyOwner {
|
||||||
owner = newOwner;
|
owner = newOwner;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user