Steven D'Aprano wrote: > result = computation( > int(arg) except ValueError: abort("Invalid int") > ) > > Actually, not quite so nice as I first thought, since you're relying on > the side-effects of abort() rather than returning a value. Yeah, while I was writing that I wondered whether you should be allowed to write int(arg) except ValueError: raise UserError("Invalid int") That looks heretical, because 'raise' can't in any way be interpreted as a value-returning expression. But you can achieve the same result using a function that always raises and exception, so forbidding it on those grounds would be pointless. And writing it that way at least makes it obvious that it *does* always raise an exception, in the same way that try: i = int(arg) except ValueError: raise UserError("Invalid int") else: result = computation(i) makes it obvious that control can't fall off the end of the except branch. -- Greg
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4