Skip to main content

Questions tagged [try-catch]

try-catch is a syntactic construct for catching exceptions raised by a code section

Filter by
Sorted by
Tagged with
1 vote
1 answer
26 views

Try Catch, Function returns x values, but returns clause has x-1 variables

Disclaimer I came across an not so well documented issue so I decided to share it and show the solution I found. This is a very simple problem with a very simple solution, I just didn't found any ...
Saucy's user avatar
  • 23
0 votes
1 answer
9 views

What counts as an external function call?

I am trying to figure out what counts as an external function call. Let's say Contract X calls function A in a third-party non-related Contract B and then that function turns around and calls function ...
user127148's user avatar
1 vote
1 answer
37 views

Why doesn't this try/catch block catch the revert in `asset.symbol`?

I wrote this Solidity function: function getAssetSymbol(IERC20Metadata asset) internal view returns (string memory) { try asset.symbol() returns (string memory symbol) { return symbol; ...
Paul Razvan Berg's user avatar
2 votes
2 answers
218 views

How can we use safeTransferFrom function in a try/catch block?

I'm trying to have a function that transfers some tokens, and if that transfer fails, stores the amount in a mapping. Since we want to account for both revertion of the transfer call and the call ...
0xNuggan's user avatar
1 vote
1 answer
92 views

Is there any way to use try/catch for the "view" functions?

I have been trying to run this code: function seeError(address _token) public view returns (uint256) { try IERC20(_token).decimals() { return IERC20(_token).decimals(); } ...
Shubham Sharma's user avatar
2 votes
0 answers
76 views

Is there any way to bubble up custom errors without using low-level assembly?

Is there any way to bubble up custom errors without using low-level assembly? Say you have a custom error defined like this: contract For { error Unauthorized(); function reverWithError() ...
Paul Razvan Berg's user avatar
0 votes
2 answers
236 views

Solidity try-catch gives expected primary expression parse error

Have the following strange problem: I'd like to implement a try-catch block in Solidity (>= 0.8.0) as follows: try myFunction(list1, 3, 0) returns (uint256 _value) { { emit Log(&...
Peter K.'s user avatar
  • 113
3 votes
1 answer
183 views

Best way to ignore the success status of a call?

I have a situation where I want to ignore the success status of a call, and I am currently doing it like this: try addr.functionCall() {} catch {} I know I could do a low-level call like this: (bool ...
Paul Razvan Berg's user avatar
1 vote
1 answer
120 views

catch errors for getting an instance of a smart contracts using address`in solidity

I tried to use the try / catch expression in order to catch errors while getting an instance of a running smart contract but it can only be used for external functions calls and contract creation ...
jutsu's user avatar
  • 143
2 votes
0 answers
387 views

Why does solidity's try/catch not catch "call to non-contract address" revertion?

Recently I encountered the issue that the try/catch command of solidity does not catch the revertion when I'm trying to call a non-contract address in the try line. While I'm aware of multiple ...
Chris's user avatar
  • 459
1 vote
1 answer
58 views

Unexpected "catch Error" Behavior

IDE: Remix (on Firefox and Brave) Compiler: v0.8.12 I am practicing with unit tests on the Ballot sample contract from Solidity's documentation, and am having trouble understanding how does catch ...
Globallager's user avatar
2 votes
2 answers
2k views

Exact behavior of state revert in `try/catch`

I'm trying to make sure I fully understand the behavior of try/catch, specifically what state gets reverted when we catch an error. I could not be sure of certain behavior from the v0.8.10 docs. If I ...
dbmikus's user avatar
  • 135
2 votes
1 answer
192 views

Does `try catch` block makes partial changes in state variable in case of error in solidity

If we consider this code below pragma solidity 0.8.0; interface testInterface{ function externalFunction(uint _test) external returns(bool); } contract abc{ uint public var1; function ...
FLAME'S KING's user avatar
0 votes
0 answers
135 views

Balance of ERC-20 Token suddenly changing to 0 in try/catch block

I'm coding a paymentsplitter that accepts LP tokens and standard tokens. If it's an LP token, it needs to convert them into the underlying assets, otherwise just split the payment. Since I only have ...
martin's user avatar
  • 126
3 votes
0 answers
501 views

Catch Internal Out of Gas Exception in Solidity Code

I ran this transaction which executed correctly, but one of the internal calls gave me back an out of gas error. I had a try/catch mechanism to let my code terminate silently (to set some really ...
Jason Trump's user avatar
22 votes
1 answer
17k views

Is it possible to perform a try-catch in Solidity?

Does Solidity support try-catch functionality? If so, how does it work? What are the limitations?
Shane Fontaine's user avatar