Created
January 29, 2025 23:25
-
-
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
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
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