Panic
*Helper library for emitting standardized panic codes.
contract Example {
using Panic for uint256;
// Use any of the declared internal constants
function foo() { Panic.GENERIC.panic(); }
// Alternatively
function foo() { Panic.panic(Panic.GENERIC); }
}
Follows the list from https://github.com/ethereum/solidity/blob/v0.8.24/libsolutil/ErrorCodes.h[libsolutil]. Available since v5.1.*
State Variables
GENERIC
generic / unspecified error
uint256 internal constant GENERIC = 0x00;
ASSERT
used by the assert() builtin
uint256 internal constant ASSERT = 0x01;
UNDER_OVERFLOW
arithmetic underflow or overflow
uint256 internal constant UNDER_OVERFLOW = 0x11;
DIVISION_BY_ZERO
division or modulo by zero
uint256 internal constant DIVISION_BY_ZERO = 0x12;
ENUM_CONVERSION_ERROR
enum conversion error
uint256 internal constant ENUM_CONVERSION_ERROR = 0x21;
STORAGE_ENCODING_ERROR
invalid encoding in storage
uint256 internal constant STORAGE_ENCODING_ERROR = 0x22;
EMPTY_ARRAY_POP
empty array pop
uint256 internal constant EMPTY_ARRAY_POP = 0x31;
ARRAY_OUT_OF_BOUNDS
array out of bounds access
uint256 internal constant ARRAY_OUT_OF_BOUNDS = 0x32;
RESOURCE_ERROR
resource error (too large allocation or too large array)
uint256 internal constant RESOURCE_ERROR = 0x41;
INVALID_INTERNAL_FUNCTION
calling invalid internal function
uint256 internal constant INVALID_INTERNAL_FUNCTION = 0x51;
Functions
panic
Reverts with a panic code. Recommended to use with the internal constants with predefined codes.
function panic(uint256 code) internal pure;