fork download
  1. class Product:
  2. def __init__(self, title, logger):
  3. self.title = title
  4. self.logger = logger
  5.  
  6. def setPrice(self, price):
  7. try:
  8. if price <= 0: raise Exception('wrong price!')
  9. self.price = price
  10. except Exception as e:
  11. self.logger.fillLog(e)
  12.  
  13. class Logger:
  14. def __init__(self):
  15. self.log = []
  16.  
  17. def makeLog(self, message):
  18. print('error: ', message)
  19.  
  20. def fillLog(self, message):
  21. self.log.append(message)
  22.  
  23. logger = Logger()
  24. product = Product('phone', logger)
  25. product.setPrice(-10)
Success #stdin #stdout 0.01s 27712KB
stdin
Standard input is empty
stdout
Standard output is empty