Skip to content

try/catch only catches the very first external call #14080

Open
@0xdavinchee

Description

@0xdavinchee

Abstract

NOTE: This seems to only be breaking if you do another external call from a contract with address(0). e.g. in the example below, if callA returns address(0).

try/catch only catches the very first external call although it allows multiple external calls to be tried. This could be a bit of a footgun if a single external call is not warned or enforced or if each of the external calls in the "try" block are not tried.

Motivation

This can be slightly confusing when you do something like: try IContractB(contractA.callA()).callB() {} catch {}
This will revert if the function callB doesn't exist on the address returned by contractA.callA.

The interfaces:

IContractA {
  function callA() external returns (address);
}

IContractB {
  function callB() external;
}

Specification

It would make more sense to:

  1. not allow multiple external calls to be tried (compiler error)
  2. try each of them separately
  3. warn that you have multiple external calls in a try "block" (compiler warning)

Backwards Compatibility

Specifications 2 and 3 would likely be backwards compatible, but Specification 1 would probably break code which violates this rule when they update their solc if this change was made.

Metadata

Metadata

Assignees

No one assigned

    Labels

    featurehigh effortA lot to implement but still doable by a single person. The task is large or difficult.high impactChanges are very prominent and affect users or the project in a major way.must haveSomething we consider an essential part of Solidity 1.0.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions