Skip to content

Instantly share code, notes, and snippets.

@jsbueno
Created September 13, 2024 12:14
Show Gist options
  • Save jsbueno/5c7f1a263dc5c28033b098d67eb499d0 to your computer and use it in GitHub Desktop.
Save jsbueno/5c7f1a263dc5c28033b098d67eb499d0 to your computer and use it in GitHub Desktop.
Python, raise exception as an expression!
# 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