Skip to main content
23 votes
Accepted

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

Solidity 0.6.0 and Greater (Updated 2020) As of Solidity 0.6.0, there is try-catch functionality built into the language. The syntax is similar to existing languages, however functionality is limited ...
Shane Fontaine's user avatar
3 votes
Accepted

Exact behavior of state revert in `try/catch`

The try/catch in solidity only check for reverts in call to another contracts. It doesn't revert state changes by itself. It only allows the caller to detect a revert in the callee. It is easy to test ...
Ismael's user avatar
  • 30.3k
3 votes
Accepted

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

As Gabriel said, safeTransferFrom is an internal function. You can use this trick to make an external call: try this.attemptTransfer(token, origin, beneficiary, amount) { emit ERC20TokensReleased(...
0xSanson's user avatar
  • 3,947
2 votes

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

Why not do something like this function seeError(address _token) public view returns (uint256) { (bool succes,) = _token.call(abi.encodePacked("decimals()")); require (success,&...
Zartaj Afser's user avatar
  • 5,320
2 votes
Accepted

Solidity try-catch gives expected primary expression parse error

just delete one of the {, you have two: try myFunction(list1, 3, 0) returns (uint256 _value) {// 1 {//2 emit Log("Success"); Hope it helps
donoso.eth's user avatar
  • 1,543
1 vote

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

Solution The solution I found is to use an temporary variable: try ContractA.getInfo() returns (uint _type, uint _id, string memory)
Saucy's user avatar
  • 23
1 vote

What counts as an external function call?

The syntax makes those external. by doing this.yourFunction() instead of simply yourFunction(), you're effectively making an external call to yourself (it's a CALL opcode, not a JUMP or a JUMPI, you ...
Foxxxey's user avatar
  • 4,457
1 vote
Accepted

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

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 ...
tenbits's user avatar
  • 2,508
1 vote

Best way to ignore the success status of a call?

With Foundry, there is a neat way to ignore Solidity compiler warnings, and that is to use the ignored_error_codes config option: # ignore solc warnings for missing license and exceeded contract size #...
Paul Razvan Berg's user avatar
1 vote

Unexpected "catch Error" Behavior

In your first vote you vote using vote(0), an internal call which keeps the same transaction context and therefore same msg.sender. In your second vote you vote using this.vote(0), an external call (...
Kenzo Agada's user avatar
  • 1,256

Only top scored, non community-wiki answers of a minimum length are eligible