Butters Butters - 1 year ago 112
Python Question

User Defined and built in Arguments in exceptions

The following code when executed doesn't result in argument( i.e : Divide by Zero is not permitted ) being printed. It only gives built in error message from-
ZeroDivisionError. So, whats the use of user defined arguments when built in error messages are available.

print "Enter the dividend"
print "Enter the divisor"

except "ZeroDivisonError",argument:
print "Divide by Zero is not permitted \n ",argument # Argument not getting printed
print "Result=%f" %(result)

Answer Source

The spelling of "ZeroDivisonError" is incorrect and moreover it shouldnt be in "". Correct line:

    except ZeroDivisionError,argument:
    print "Divide by Zero is not permitted \n ",argument