python - IF and ELSE Exception in Python3 -



python - IF and ELSE Exception in Python3 -

i trying grab exception 2 boolean (for if , else separately).

this working on:

from math import * decimal import decimal def add(self, *args): try: if all(isinstance(n, int) n in args): print(sum(int(n) n in args)) else: print(fsum(decimal(n) n in args)) except (nameerror, syntaxerror) e: print("error! {}".format(e)) def main(): add(a) if __name__ == '__main__': main()

both if , else gives me 2 exceptions nameerror , syntaxerror, if give add(a) giving me nameerror exception. except not catching error.

how should grab exception both of them separately?

from understand think can seek this.

except nameerror e : print "name error occured" print("error! {}".format(e)) except syntaxerror f: print "syntax error occurred" print("error! {}".format(f))

python python-3.x exception-handling

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -