>>> class NegativeDivisionError(Exception): << 사용자정의 예외 정의
def __init__(self, value):
self.value = value
>>> def PositiveDivide(a, b):
if(b < 0):
raise NegativeDivisionError(b) << 제수가 0보다 적은 경우 NegativeDivisionError 발생
return a / b
>>> try:
ret = PositiveDivide(10, -3)
print('10 / 3 = {0}'.format(ret))
except NegativeDivisionError as e:
print("Error - Second argument of PositiveDivide is ", e.value)
except ZeroDivisionError as e:
print("Error - ", e.args[0])
except:
print("Unexpected exception")
Error - Second argument of PositiveDivide is -3