Skip to content

Instantly share code, notes, and snippets.

@bbelderbos
Created August 9, 2023 11:35
Show Gist options
  • Save bbelderbos/a2fdbd62fa6fcf1eccb3e3edf987255d to your computer and use it in GitHub Desktop.
Save bbelderbos/a2fdbd62fa6fcf1eccb3e3edf987255d to your computer and use it in GitHub Desktop.
class TransactionLimitExceededError(Exception):
"""Raised when a transaction exceeds the allowed limit."""
def __init__(self, amount, limit):
self.amount = amount
self.limit = limit
super().__init__(f"Transaction amount of {amount} exceeds the limit of {limit}.")
try:
raise TransactionLimitExceededError(500, 200)
except TransactionLimitExceededError as e:
print(f"Attempted transaction of {e.amount} exceeds the limit of {e.limit}.")
# outputs:
# Attempted transaction of 500 exceeds the limit of 200.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment