I wrote this Solidity function:

function getAssetSymbol(IERC20Metadata asset) internal view returns (string memory) {
    try asset.symbol() returns (string memory symbol) {
        return symbol;
    } catch {
        return "ERC20";

And, while testing it, I realized that reverts are not caught when:

  • asset is an address that doesn't contain code
  • asset returns a bytes32 instead of string (e.g. the MKR token does this)

Why is that? I was expecting try/ catch to handle these reverts.

1 Answer 1


try..catch doesn't catch the boundary exceptions, just the inner method call. Exactly that, what you have mentioned:

  • checks if address is not void
  • checks if extcodesize exists
  • --checks if method exists-- This will be caught.

Any fails at this steps cause the revert. After the method is executed:

  • checks if the return is as expected and can be decoded

A failure at this step also causes the revert.

Additional infos: try-catch

Sorry, initially I've written it reverts if the method does not exist. I was not sure about that and I was wrong, the call to an unexisting method will be caught. I think the method invocation is already at the inner contract level, as it executes a fallback method if any, otherwise reverts, which will be caught by the try..catch

  • Sorry Paul, the nonexisting method call will be caught by the try..catch
    – tenbits
    Commented May 24, 2023 at 12:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.