Skip to content

Instantly share code, notes, and snippets.

@CJ42
Last active March 26, 2023 14:33
Show Gist options
  • Save CJ42/7372a68e4d4dd83affa0fc491b451a87 to your computer and use it in GitHub Desktop.
Save CJ42/7372a68e4d4dd83affa0fc491b451a87 to your computer and use it in GitHub Desktop.
// 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