(License: CC BY-SA 4.0)
If statement:
value = count_inputs(...)
if value < -1:
print("Error in counting inputs!")
exit -1
# now do stuff with value
...
Exception:
try:
value = count_inputs(...)
# now do stuff with value
...
except:
print("Error in counting inputs!")
raise
BaseException
import sys
try:
f = open('myfile.txt')
s = f.readline()
i = int(s.strip())
except OSError as err:
print("OS error: {0}".format(err))
except ValueError:
print("Could not convert data to an integer.")
except:
print("Unexpected error:", sys.exc_info()[0])
raise
else:
print("OMG no errors!")
finally:
print("Error or not, I say this.")
Individually or in teams, implement ONE of these by using exceptions:
defaultdict
functionality by using the regular dict
Attach runtime output screenshots showing valid and exception cases on submission site.