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 ...
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 ...
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(...
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,&...
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
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)
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 ...
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 ...
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
#...
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 (...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
try-catch × 17solidity × 16
revert × 3
contract-invocation × 2
error × 2
contract-development × 1
truffle × 1
remix × 1
erc-20 × 1
truffle-test × 1
hardhat × 1
out-of-gas × 1
assembly × 1
internal-transactions × 1
solidity-0.6.x × 1
solidity-0.8.x × 1
revert-opcode × 1
unittesting × 1
remix-tests × 1
keyword × 1
custom-errors × 1