The below code produces exception while handling non int
values but it doesn't continue the loop but rather comes out from the loop raising error. My intention is to provide the value of 0 for exception cases.
Sample Input:
Common Ruby Errors 45min
Rails for Python Developers lightning
Code:
class TimeNotProvidedError(Exception):
pass
def extract_input():
lines = []
__tracks = {}
try:
lines = [line.strip() for line in open('test.txt')]
except FileNotFoundError as e:
print("File Not Found", e)
for line in lines:
title, minutes = line.rsplit(maxsplit=1)
minutes = int(minutes[:-3])
try:
__tracks[title] = minutes
except TimeNotProvidedError:
__tracks[title] = 0
return __tracks
print(extract_input())
Traceback:
ValueError: invalid literal for int() with base 10: 'lightn'