Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
28459 Discussions

Clear error after call to GETLASTERRORQQ

DavidWhite
Valued Contributor II
377 Views
I am trying to detect when a file on a network drive is accessible. I can detect when there is a problem using GETFILEINFOQQ and GETLASTERRORQQ. I then get the app to wait for a period and then retry. If the resource is available, then GETFILEINFOQQ is successful, but the last error is still reported.

Is there any way to clear the last error once the error has been handled (by waiting in my example)?

Thanks,

David
0 Kudos
7 Replies
onkelhotte
New Contributor II
377 Views
Quoting - David White
I am trying to detect when a file on a network drive is accessible. I can detect when there is a problem using GETFILEINFOQQ and GETLASTERRORQQ. I then get the app to wait for a period and then retry. If the resource is available, then GETFILEINFOQQ is successful, but the last error is still reported.

Is there any way to clear the last error once the error has been handled (by waiting in my example)?

Thanks,

David

Why dont you use the handle that GETFILEINFOQQ returns? It has the value FILE$ERROR if the file dont exist...

When debug, in the first run it steps into i=1, then I copy the file, debug further and then I geti=2.

Markus

[cpp]handle = FILE$FIRST
result = GETFILEINFOQQ (files, info, handle)
if(handle==file$error) then
    i = 1
else
    i = 2
end if

! copying file to the right dir

handle = FILE$FIRST
result = GETFILEINFOQQ (files, info, handle)
if(handle==file$error) then
    i = 1
else
    i = 2
end if[/cpp]
0 Kudos
DavidWhite
Valued Contributor II
377 Views
Quoting - onkelhotte
Why dont you use the handle that GETFILEINFOQQ returns? It has the value FILE$ERROR if the file dont exist...

I wanted more specific information about the cause of the error, so I was using GETLASTERRORQQ. However my logic in checking for FILE$ERROR was incorrect, which meant I was checking the last error even when the last call had not flaggedan error.

Thanks,

David
0 Kudos
onkelhotte
New Contributor II
377 Views
Quoting - David White

I wanted more specific information about the cause of the error, so I was using GETLASTERRORQQ. However my logic in checking for FILE$ERROR was incorrect, which meant I was checking the last error even when the last call had not flaggedan error.

Thanks,

David

Youre right, this doesnt solve the GETLASTERRORQQ problem... But finding your file problem ;-)

So, when you use a function or subroutine, that can produce an error that is recognised by GETLASTERRORQQ you cannot say if it is the same error (and the result has the same value) or if there was no error at all and the value doesnt change because of that. Doesnt the doctor have a cure or suggestion?

Markus
0 Kudos
Steven_L_Intel1
Employee
377 Views
I don't know of a way to clear the error code, but you might consider the Win32 API GetLastError() to see if it better meets your needs. However, I generally don't ask for the "last error" unless an operation has returned to me with a status saying it failed. Calling GETLASTERRORQQ repeatedly does not seem to me to fit in with its design.
0 Kudos
g_f_thomas
Beginner
377 Views
Quoting - David White
I am trying to detect when a file on a network drive is accessible. I can detect when there is a problem using GETFILEINFOQQ and GETLASTERRORQQ. I then get the app to wait for a period and then retry. If the resource is available, then GETFILEINFOQQ is successful, but the last error is still reported.

Is there any way to clear the last error once the error has been handled (by waiting in my example)?

Thanks,

David

Use the Win API. IIRC do something like

errres=GetLastError()
Call SetLastError(errres)

Gerry
0 Kudos
DavidWhite
Valued Contributor II
377 Views
Quoting - g.f.thomas

Use the Win API. IIRC do something like

errres=GetLastError()
Call SetLastError(errres)

Gerry
Gerry,

I think it will actually need
Call SetLastError(0)
to clear the error.

David
0 Kudos
g_f_thomas
Beginner
377 Views
Quoting - David White
Quoting - g.f.thomas

Use the Win API. IIRC do something like

errres=GetLastError()
Call SetLastError(errres)

Gerry
Gerry,

I think it will actually need
Call SetLastError(0)
to clear the error.

David

I more or less agree. The last time I used this I did

USE IFWINTY
USE KERNEL32
IF(GETLASTERROR() /= ERROR_SUCCESS) CALL SETLASTERROR(ERROR_SUCCESS)

Gerry
0 Kudos
Reply