Как узнать, произошло ли исключение в методе класса родителя, переопределив тот же метод в дочернем классе?
class Customer:
def withdraw(self, amount):
if self.__account_balance < self.get_min_balance:
raise LimitException()
class PrivCustomer(Customer):
def withdraw(self, amount):
""" here how do I detect if an exception has occurred in the withdraw method of Customer class ?""""
Метод PrivCustomer.withdraw
заменит метод Customer.withdraw
для объектов PrivCustomer
. Чтобы вызвать Customer.withdraw
, вы должны использовать super().withdraw
чтобы получить унаследованный метод. Этот вызов метода будет LimitException
class PrivCustomer(Customer):
def withdraw(self, amount):
try:
super().withdraw(amount)
except LimitException:
...
try
? docs.python.org/3/tutorial/errors.html#handling-exceptions