24 lines
561 B
Python
24 lines
561 B
Python
def handleZeroDivisionError(lmbd):
|
|
def runlambda(*args,**kwargs):
|
|
try:
|
|
return lmbd(*args,**kwargs)
|
|
except ZeroDivisionError:
|
|
print("Zero division detected!")
|
|
return runlambda
|
|
|
|
# usage: handleZeroDivisionError(lambda)()
|
|
# or:
|
|
|
|
@handleZeroDivisionError
|
|
def div(a,b):
|
|
return a/b
|
|
|
|
def main():
|
|
print(handleZeroDivisionError(lambda:1/0)())
|
|
print(handleZeroDivisionError(lambda:1/1)())
|
|
print(div(1,0))
|
|
print(div(1,1))
|
|
return 0
|
|
|
|
if __name__ == '__main__':
|
|
main() |