Having trouble translating the following two specifications to Python code. I'm finding the terminology is strange for a Python program (throw, catch, contents of exception).
First specification states "If the file can't be opened because it does not exist, you must catch the FileNotFoundError object and throw a new exception FileNotFoundError with the contents of the exception being the filename. Any other exception for failure to open is not caught. filename is sent into a function.
I translated this as...
try:
f = open(filename)
except FileNotFoundError(filename):
raise FileNotFoundError(filename)
I ask as I've already said; the terminology is strange; the "contents of the exception being the filename" for example.
Also, the other specification being that if the parameter filename is not a string type, then a TypeError exception is thrown with the contents of the exception being a string "parameter filename is not a string".
Again, the "contents of the exception"?
My translation for that specification is...
x = isinstance(filename, (str))
if x == False:
raise TypeError('parameter filename is not a string')