The revert statement

The revert statement is very similar to the require function. However, it does not evaluate any statement and does not depend on any state or statements. Hitting a revert statement means an exception is thrown, along with the return of unused gas, and reverts to its original state.

In the following example, an exception is thrown when the incoming value is checked using the if condition; if the if condition evaluation results in false, it executes the revert function. This results in an exception and execution stops, as shown in the following screenshot:

Get Solidity Programming Essentials now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.