I'm writing a code that uses files. I want to check if the name of the files are empty string, and if so to raise a ValueError. Moreover, I want to close all the files, no matter what
- Can I raise a ValueError before the "try" block of the code?
Is it OK to write the code only with "try" and "finally"?
`def functio(file_1, file_2):
if file_1 == '' or file_2 == '': raise ValueError("Invalid input") try: ~rest of the code~ finally: if file_1 =! None or file_2 != None: file_1.close() file_2.close()`