Python not catching exception -
for reason code not catching exception when throw it. have
def trim_rad(rad): ... if not modrad.shape[0]: raise indexerror("couldn't find main chunk") return modrad, thetas
then later call function:
try: modrad, thetas = trim_rad(rad) except indexerror("couldn't find main chunk"): return 0
yet still traceback exception. doing wrong?
you gave except
instance of indexerror
. instead:
try: modrad, thetas = trim_rad(rad) except indexerror: print "couldn't find main chunk" return 0
here example:
>>> try: ... [1][1] ... except indexerror('no'): ... pass ... traceback (most recent call last): file "<stdin>", line 2, in <module> indexerror: list index out of range >>> try: ... [1][1] ... except indexerror: ... pass ... >>>
Comments
Post a Comment