I've got this snippet of code in a private class procedure which is called by the Class constructor.
When I deliberately pass a file that doesn't exist....
try
try
AssignFile(Settings, SettingsFile);
Reset(Settings); // This generates the exception
//Statements
except
on e: EFileNotFoundException do // This code check fails and the else part is executed
writeln (DateToSTR(Date),':', TimeToSTR(Time),':', 'File Not Found :'+SettingsFile);
else
Raise; // This executes
end;
finally
try // I'm not sure this is the correct approach....
Close(Settings);
except
on E: Exception do writeln (DateToSTR(Date),':', TimeToSTR(Time),':', 'File Not Closed :'+SettingsFile); // This executes and writes to the console.
end;
The exception
doesn't appear to be the correct one.
The final exception raised is:
EInOutError: File not found
Should I use
instead of
?
How do I differentiate between other kinds of input/output errors in my exception handling?
I want code execution to terminate when the file isn't found.