# Error Handling (assert / require / revert / try-catch)
Solidity++ uses state-reverting exceptions to handle errors. Such an exception undoes all changes made to the state in the current call (and all its sub-calls) and flags an error to the caller.
Error propagation through
revert
andtry/catch
will be supported in v0.8.1.
assert(bool condition)
causes a Panic error and thus state change reversion if the condition is not met - to be used for internal errors.
require(bool condition)
reverts if the condition is not met - to be used for errors in inputs or external components.
require(bool condition, string memory message)
reverts if the condition is not met - to be used for errors in inputs or external components. Also provides an error message.
revert()
abort execution and revert state changes
revert(string memory reason)
abort execution and revert state changes, providing an explanatory string
The following example shows how to use an error string together with revert
and the equivalent require
:
If you provide the reason string directly, then the two syntax options are equivalent, it is the developer's preference which one to use.
For more examples please refer to https://docs.soliditylang.org/en/v0.8.1/control-structures.html?highlight=panic#error-handling-assert-require-revert-and-exceptions (opens new window)