Почему не ловят ServerError
?Я вынужден поймать общий Exception
и проверить, соответствует ли его тип ожидаемому типу ошибки.
Ниже приведено упрощение более крупного проекта, над которым я работаю.
class GeneralException(Exception):
def __init__(self):
pass # Do something
class ServerError(GeneralException):
def __init__(self, args):
GeneralException.__init__(self, args)
try:
# something that raises Exception
# except ServerError as e: # DOES NOT CATCH
except Exception as e:
if type(e) is type(ServerError()): # This works
break
raise