Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Re-try with TRY/CATCH
Message
De
16/12/2008 13:58:37
 
 
À
16/12/2008 03:16:54
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Versions des environnements
Visual FoxPro:
VFP 9 SP2
OS:
Windows XP
Network:
Windows 2003 Server
Database:
MS SQL Server
Divers
Thread ID:
01367724
Message ID:
01367928
Vues:
9
This message has been marked as a message which has helped to the initial question of the thread.
>>>>Hi everybody,
>>>>
>>>>I have the following code
>>>>
>>>>TRY
>>>>	&tcSql
>>>>CATCH TO loEx
>>>>	_CLIPTEXT = m.tcSql
>>>>	IF loEx.Error = 108 && File is in use by another user
>>>>	   DECLARE INTEGER Sleep IN Win32API INTEGER cMilliseconds
>>>>	   =Sleep(0.5*1000) && wait half a second
>>>>	ENDIF  
>>>>       * more code here
>>>>ENDTRY
>>>>
>>>>Basically in the IF loEx.Error check I want to re-try the original statement and if it fails again execute the same logic as in my main catch block. How can I code such "recursion" ?
>>>>
>>>>Thanks a lot in advance.
>>>
>>>
>>>That would be in a do-while (or for/next) loop I take it
>>
>>Thanks, I'll go with FOR/NEXT.
>>
>>Something like
>>
>>FOR lnI = 1 TO 2
>>	TRY
>>		&tcSql
>>	CATCH TO loEx
>>		_CLIPTEXT = m.tcSql
>>		IF lnI = 1 AND loEx.ERROR = 108  && File is in use by another user
>>
>>			DECLARE INTEGER Sleep IN Win32API INTEGER cMilliseconds
>>			=Sleep(0.5*1000) && wait half a second
>>** we're going to re-try
>>		ELSE
>>                                               * the normal catch code
>>                                               lnI = 10 && to fall out the loop
>>                                          ENDIF
>>                         ENDTRY
>>NEXT
>
>(1) What if there's no error ?
>(2) I prefer EXIT instead of lnI = 10

Hi Gregory,
an EXIT within TRY ENDTRY doesn't break the loop.

> - more readable
> - what if you decide to try 10 or 15 times (or step -1) and forget to change lnI = 10 ?
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform