Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Catching and Handling File Access Denied error in a Try-Catch-EndTry 2

Status
Not open for further replies.

PatMcLaughlin

Programmer
Dec 10, 2010
97
US
I need to find a way to catch the error #1705 in a process that is used extensively by my company. If it is caught, I want it to try the process again, 1 more time. The process is after a file has completed its processing, it is moved to a 'done' folder or if there was an error, moved to an 'error folder' Due to problems we are currently experiencing with a slow network, this will occasionally fail with the Access Denied error. On inspection, we find that the file did everything except report the move to the log. If we rerun the file, without change, it will run without error. Any ideas?
 
Not sure what your question is. Are you asking how to use TRY / ENDTRY to catch that error? Ff so, it goes something like this:

Code:
LOCAL loError, lnError
lnError = 0
TRY
  * Execute the commands that might give rise to the error
CATCH TO loError
  lnError = loError.ErrorNo
ENDTRY

* lnError now contains the error number, if any
DO CASE
  CASE lnError = 1705
    * File access denied
  CASE lnError = 0
    * No error
  OTHERWISE
    * Some other error
ENDCASE

If I have misunderstood your question, my apologies. Perhaps you could clarify it.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
The traditional way to handle this is with RETRY in your ON ERROR routine. Do you have an ON ERROR routine?
 
Since you want to handle one error differently than the rest, I think I'd modify Mike's code to use CATCH WHEN

Code:
LOCAL loError, lnError
lnError = 0
TRY
  * Execute the commands that might give rise to the error
CATCH TO loError WHEN loError.ErrorNo = 1705
  * Do your retry or set a flag to go back and retry
CATCH TO loError
  * Handle all other errors
ENDTRY

Tamar
 
Actually SET REPROCESS does what you want to redo on your own. You may just have another timeout between retries.

Bye, Olaf.
 
Between Mike and Tamar I have a process that appears to be working as I envisioned. Thanks for the quick posts!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top