Solution: Exception int conversion (all other)



examples/exceptions/handle_all_other_exceptions.py
import sys
import module

# python handle_both_exceptions.py one.txt zero.txt two.txt three.txt
files = sys.argv[1:]

for filename in files:
    try:
        module.read_and_divide(filename)
    except ZeroDivisionError:
        print("Cannot divide by 0 in file {}".format(filename))
    except IOError:
        print("Cannot open file {}".format(filename))
    except Exception as ex:
        print("Exception type {} {} in file {}".format(type(ex).__name__, ex, filename))

before one.txt
100.0
after  one.txt
before zero.txt
Cannot divide by 0 in file zero.txt
before two.txt
Cannot open file two.txt
before text.txt
Exception type ValueError invalid literal for int() with base 10: '3.14\n' in file text.txt
before three.txt
33.333333333333336
after  three.txt