Last active
July 19, 2023 14:25
-
-
Save deliriusz/6c05146893083b344fc859b49928b984 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; | |
import "hardhat/console.sol"; | |
contract TryCatchCaller { | |
TryCatchCallee calee; | |
constructor () { | |
calee = new TryCatchCallee(); | |
} | |
function callMe() public { | |
console.log("inside TryCatchCaller.callMe()"); | |
} | |
function test() public { | |
try calee.test() { | |
console.log("TryCatchCallee.test() ran successful"); | |
} catch { | |
console.log("TryCatchCallee.test() failed"); | |
} | |
} | |
// will not compile | |
function test2() public { | |
try callMe() { | |
console.log("TryCatchCaller.callMe() ran successful"); | |
} catch { | |
console.log("TryCatchCaller.callMe() failed"); | |
} | |
} | |
// totally ok | |
function test3() public { | |
try TryCatchCaller(address(this)).callMe() { | |
console.log("TryCatchCaller.callMe() ran successful"); | |
} catch { | |
console.log("TryCatchCaller.callMe() failed"); | |
} | |
} | |
// totally ok | |
function test4() public { | |
try this.callMe() { | |
console.log("this.callMe() ran successful"); | |
} catch { | |
console.log("this.callMe() failed"); | |
} | |
} | |
} | |
contract TryCatchCallee { | |
function test() public { | |
console.log("inside TryCatchCallee.test()"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment