-
Notifications
You must be signed in to change notification settings - Fork 6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unable to use try
/catch
to catch local reverts in extra code generated for high-level external calls
#13869
Comments
This issue is a major use-case of the #12725 issue. |
I think we should extend the try/catch statement in the following way (which is backwards-compatible): Currently, we allow the following catch statements:
We can easily extend these to capture the two additional cases of "contract does not exist" and "abi decoding failure" by adding more catch statements:
In order to make this easier to use and also backwards-compatible, we could also add
In the end, this could at some point maybe be replaced by some kind of destructuring / match expression, and both NoContract and DecodingFailure could be specific identifiers that need to be defined in the standard library. |
Here's my proposal from the call, adapted a bit to cover also all @chriseth is proposing above:
|
try
/catch
to catch local reverts in extra code generated for high-level external calls
I think we should avoid extending I would rather prefer re-adding the Alternatively, we should create a primitive that allows completely getting rid of |
But that's breaking, isn't it? I think the idea of bringing it up now was to patch it to make it actually usable without breaking its current semantics.
That's a good idea too if we're fine deprecating |
Just generally: We can still decide to only change this for 0.9, doing anything here non-breakingly would be nice, but we shouldn't constrain ourselves by it. A "silent" change in behaviour for the default clause without any prior change or notice is harsh even for a breaking release though (by no means a no-go, but it is a heavy thing to do). Something like |
We talked about [call for feedback] The future of The decision on the call was basically to wait for user feedback on these proposals and maybe implement the short term ones, but also keep in mind that in the long term we'll likely want to replace |
I guess we still don't have any update on this in 2024? |
How can we call an external code, and reliably catch errors?
Consider the following code, which tries to create "
safeBalance
" method, which calls balanceOf and never reverts.(spoiler:
try/catch
doesn't catch a lot of cases)But....
address(0)
)So basically, we can't rely on try/catch ...
The only alternative is to resort to low-level call (
address.call()
) and manually parse the result - inrealSafeBalance()
This solution is error-prone, type-unsafe and more expensive in its gas usage.
The text was updated successfully, but these errors were encountered: