I am trying to catch an exception for two boolean (for if and else separately).
this is what I am working on:
from math import *
from decimal import Decimal
def add(self, *args):
try:
if all(isinstance(n, int) for n in args):
print(sum(int(n) for n in args))
else:
print(fsum(Decimal(n) for n in args))
except (NameError, SyntaxError) as e:
print("Error! {}".format(e))
def main():
add(a)
if __name__ == '__main__': main()
Both if and else gives me two exceptions NameError
and SyntaxError
, if I give add(a)
its giving me NameError
as the exception. But the except
is not catching the error.
How should I catch the exception for both of them separately?