Solidity REPL
Debugging & errors

Typed catch clauses

Handle Error(string) and Panic(uint256) from external calls separately.

Solidity 0.8.36REPL mode

Why use this example

Use this pattern to reproduce a failure or follow an execution from Solidity source into calls and EVM opcodes. The entry isolates typed catch clauses so its input, result, and state changes stay easy to compare.

Solidity to run

contract FailureModes {
  function fail(uint256 mode) external pure returns (uint256) {
    if (mode == 1) revert("reason");
    if (mode == 2) assert(false);
    return 42;
  }
}
contract FailureCatcher {
  function run(FailureModes target, uint256 mode) external returns (uint256) {
    try target.fail(mode) returns (uint256 value) { return value; }
    catch Error(string memory) { return 1; }
    catch Panic(uint256) { return 2; }
    catch { return 3; }
  }
}

FailureModes failures = new FailureModes()
FailureCatcher catcher = new FailureCatcher()
catcher.run(failures, 1)
catcher.run(failures, 2)
catcher.run(failures, 0)

Official Solidity reference

Compare this focused investigation with the complete language definition in the Solidity documentation.

Try and catch

What to expect

The string error reaches catch Error and returns 1, the assertion reaches catch Panic and returns 2, and the successful call returns 42.

Continue the investigation

Change a value, add another expression, or open Inspect after the run. Accepted entries remain available to the next entry, and the clean replay keeps the complete result reproducible.

Read about debugging Execution diagnosis