I am new to "Try & Except" so sorry if my question is very novice. I tried to search the reason but didn't find any.
I am trying a very simple Try an Except for read_csv:
try:
cntrl = pd.read_csv(my_directory + file, sep='|')
except FileNotFoundError:
logger.critical("file not found")
logger.info(f"file imported. Number of records: {len(cntrl )}")
So, when I don't have the file, the try and except just prints the error and moves to next line of "logger.info" code to give the below error.
UnboundLocalError: local variable 'cntrl' referenced before assignment
Shouldn't the code stop when error is found and not move to next? When I run the read_csv code without try and except, it stops and throws the error as FileNotFound.