lessonΒ·25 minΒ·Chapter 3 of 3
Error Handling
Solidity provides three mechanisms for error handling: `require()` validates inputs and conditions (refunds remaining gas), `revert()` with custom errors is gas-efficient, and `assert()` checks for invariants that should never be false. Custom errors (introduced in Solidity 0.8.4) save gas: `error InsufficientBalance(uint256 available, uint256 required);`. Use `try/catch` for handling errors from external calls. All state changes are reverted on error.
π‘ Key Takeaway
This lesson covers the fundamental concepts. Make sure you understand these before moving to the next chapter.