Skip to content

Instantly share code, notes, and snippets.

@mcsee
Created January 29, 2025 23:25
Show Gist options
  • Save mcsee/8594a2641887d973c8b7b397d1facdab to your computer and use it in GitHub Desktop.
Save mcsee/8594a2641887d973c8b7b397d1facdab to your computer and use it in GitHub Desktop.
This gist belongs to Clean Code Cookbook http://cleancodecookbook.com By Maximiliano Contieri http://maximilianocontieri.com
class KlendathuInvasionError(Exception):
def __init__(self, message):
super().__init__(message)
def deploy_troops(safe):
if not safe:
raise Exception("Drop zone is hot!")
# You throw the exception
print("Troopers deployed.")
try:
deploy_troops(False)
except KlendathuInvasionError as e:
print(f"Abort mission: {e}")
# You handle the exception
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment