Last active
March 26, 2022 16:04
-
-
Save nmushegian/de35e6a389b12da4f9bc1a828b44c5a6 to your computer and use it in GitHub Desktop.
This file contains 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
``` | |
// This code snippet shows how an external function can use a pattern like | |
// python's `try..except..else` with `.call`, `throw`, and reentry | |
contract TryExceptElsePatternUser { | |
address _sender; | |
function tryExceptElsePatternExample() | |
external // must be external | |
{ | |
if( msg.sender == address(this) ) { | |
// `try` body - runs at +1 depth, msg.sender is this, true sender in storage | |
} else { | |
_sender = msg.sender; | |
if( !this.call(msg.data) ) { | |
// `except` body, run if "try" body throws | |
} else { | |
// `else` body - run if there is no exception | |
} | |
// EDIT: `finally`? body? I think it is not correct but can't remember why | |
} | |
} | |
} | |
``` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@nmushegian do you think this will work with latest EVM?