Re: Can't understand why these exceptions occur...



Jamie <jamie_ka1lpa_not_valid_after_ka1lpa_@xxxxxxxxxxx> wrote in
news:sHh0k.153$%54.143@xxxxxxxxxxxx:

<snip>
Please Disable the io trap {$I-}

Ok, I've added {$I-} to the top of my program.

and use the IOResult after each Read/write
function... to test...

I've made the following changes as well:
--- load cache ---
procedure LoadCache(Const cacheName : String);
var
cache : File of TBufferInfo;
begin
try
if FileExists(cacheName) then
begin
AssignFile(cache, cacheName);
if IOResult <> 0 then WriteLn(IOResult);
Reset(cache);
if IOResult <> 0 then WriteLn(IOResult);
idx := 1;
while Not(eof(cache)) and (idx < Length(files)) do
begin
Read(cache, files[idx]);
if IOResult <> 0 then WriteLn(IOResult);
Inc(idx);
end;
CloseFile(cache);
if IOResult <> 0 then WriteLn(IOResult);
end;
except on e : Exception do
WriteLn('Exception occured: ' + e.Message);
end;
Exit;
end;

--- save cache ---
procedure SaveCache(Const cacheName : String);
var
cache : File of TBufferInfo;
begin
try
AssignFile(cache, cacheName);
if IOResult <> 0 then WriteLn(IOResult);
ReWrite(cache);
if IOResult <> 0 then WriteLn(IOResult);
idx := 1;
while (idx < Length(files)) do
begin
if (files[idx].name <> '') then
begin
Write(cache, files[idx]);
if IOResult <> 0 then WriteLn(IOResult);
end;
Inc(idx);
end;
CloseFile(cache);
if IOResult <> 0 then WriteLn(IOResult);
except on e : Exception do
WriteLn('Exception occured: ' + e.Message);
end;
end;

--- main ---
if IOResult <> 0 then WriteLn('before load ' + IntToStr(IOResult));
LoadCache('FileLocatorBuffer.dat');
if IOResult <> 0 then WriteLn('after load ' + IntToStr(IOResult));

if LowerCase(ParamStr(1)) = 'buffer' then
begin
if IOResult <> 0 then WriteLn('before buffer ' + IntToStr(IOResult));
StartBufferingFiles(ParamStr(2));
if IOResult <> 0 then WriteLn('after buffer ' + IntToStr(IOResult));
end;

if IOResult <> 0 then WriteLn('before save ' + IntToStr(IOResult));
SaveCache('FileLocatorBuffer.dat');
if IOResult <> 0 then WriteLn('after save ' + IntToStr(IOResult));
---

So whenever IOResult is not 0, it should be written inside the console
screen. This never happens, even though exceptions are still thrown. I've
now noticed the exception I/O error 103. A quick Google led me to the
following page
(http://www.faqts.com/knowledge_base/view.phtml/aid/24059/fid/175) where
it is said that:

"A file is assigned and then closed, but the file pointer has not
(for all possible cases) been reset or rewritten, in between."

Which is not the case here. Later on I read:

"This can also be raised if you are trying to write out to a path that
does not exist."

Still not the case.

also...
If IoResult is not 0 , forwarding Pascal IO
functions will fail!

I'm afraid I don't really understand what you're saying here.

I use InOUtRes := 0 when I know the error has
been handled if I don't want to use the IoResult
using the IoResult clears the error after it returns
the current error value.
the InOutRes is the variable that holds it.
On entry, you should always do
InOutRes := 0;
to make sure you don't have any errors from some where else
lingering.

If I add InOutRes := 0 in any of the procedures, I get an error stating
that InOutRes is not a variable.

Thanks,

Ikke
.



Relevant Pages

  • Re: Cant understand why these exceptions occur...
    ... If Ioresult 0 THen WriteLn, ... procedure LoadCache(Const cacheName: String); ... while Not) and (idx < Length(files)) do ... except on e: Exception do ...
    (alt.comp.lang.borland-delphi)
  • Re: Cant understand why these exceptions occur...
    ... If Ioresult 0 THen WriteLn, ... If INoutRes 0 then ... procedure LoadCache(Const cacheName: String); ... while Not) and (idx < Length(files)) do ...
    (alt.comp.lang.borland-delphi)
  • Re: Cant understand why these exceptions occur...
    ... AssignFile(cache, cacheName); ... while Not) and (idx < Length(files)) do ... If IoResult is not 0, ... the InOutRes is the variable that holds it. ...
    (alt.comp.lang.borland-delphi)
  • Re: IO 32 and 103 error
    ... Cause the IOResult only contains the result of the last ... you mention old term like 'PASCAL file system' and I/O.. ... > and clear the internal IO error value which is InOutRes ... > set it to a non zero state.. ...
    (alt.comp.lang.borland-delphi)
  • Re: Cant understand why these exceptions occur...
    ... It clears the state after each read. ... If Ioresult 0 THen WriteLn, ... If you don't have InOutRes to directly set it at the start. ... write a log Error Log Function... ...
    (alt.comp.lang.borland-delphi)