ok, when the user types in a non-exist file name, the program simply shut down. i dont know what happen

procedure set_up;
begin
write('file');readln(file);
assign(f,file); reset(f);
{$I-}if IOresult<>0 then writeln('NO File....');
close(f);{$I+}
end;
....
{this is the main program}
begin
setup;
end

this proceure is called in the main program ,yet, runtime error occurs and the screen just flashes out. it works perfectly when i type in the correct filename. i need your help!!!

grace

Recommended Answers

All 2 Replies

Hi,

You must put the IO Checking off flag before the assign statement otherwise the exception occurs before you can check it;

catch the reset(filevar)

{$I-}
reset(f);
{$I+}
if ioresult <> 0 then writeln('error when trying to open the file');
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.