Last active
March 26, 2023 14:33
-
-
Save CJ42/7372a68e4d4dd83affa0fc491b451a87 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: GPL-3.0 | |
pragma solidity ^0.8.0; | |
contract TryCatchExamples { | |
function tryCatchExternalCall(address target) public { | |
try Target(target).doSomething() returns (string memory) { | |
} catch { | |
} | |
} | |
function tryDeployingContract() public { | |
try new Target() returns (Target) { | |
} catch { | |
} | |
} | |
} | |
contract Target { | |
uint256 _callCounter; | |
function doSomething() public returns (string memory) { | |
_callCounter++; | |
return "state updated successfully"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment