Created
September 13, 2024 12:14
-
-
Save jsbueno/5c7f1a263dc5c28033b098d67eb499d0 to your computer and use it in GitHub Desktop.
Python, raise exception as an expression!
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
# Usually an exception can be raised with the `raise` statement | |
# | |
# however, occasionally it can be useful to be able to do so as part | |
# of an expression (even if the occasion is code golphing). | |
# A workaround for that is achievable through a generator's | |
# `.throw` method: | |
(_ for _ in ()).throw(Exception()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment