Sometimes receiving an error is an indication, that something isn't in the stat you expect it to be. So we have introduced the new tag CFRETRY. It comes with a set of jump statements which will be introduced in Railo 4.1 and which we will be blogging about soon. So let's start with CFRETRY.
CFRETRY will do exactly what the name states. It will try to reexecute the code framed by the CFTRY tag it is used in. So consider the following code:
<cftry>
<cffile action="copy" source="C:\test.xml" destination="d:\susi\test.xml">
<cfcatch>
<cfif not directoryExists("d:\susi")>
<cfdirectory action="create" directory="d:\susi">
<cfretry>
</cfif>
</cfcatch>
</cftry>
Next to the tag CFRETRY there also exists the statement retry which you can use inside CFSCRIPT as well. The use cases for tag CFRETRY are numerous. It is another tool you can use for structuring your application and improve the code quality. Comments are as usual warmly welcome.
11 responses so far ↓
1 Michael Zock // Nov 27, 2012 at 4:40 AM
2 Peter Pham // Nov 27, 2012 at 10:44 AM
3 spills // Nov 27, 2012 at 4:37 PM
4 Gert Franz // Nov 27, 2012 at 4:58 PM
Gert
5 Michael Zock // Nov 27, 2012 at 5:19 PM
6 Simon Wright // Dec 5, 2012 at 2:10 AM
When the number of retries fails, I see two possible options: either the retry becomes inert and execution continues as normal... or we specify a throw parameter and allow a different catch block to handle that scenario.
I think the former is the cleaner and more flexible option.
7 Tom // Jan 11, 2013 at 10:21 PM
8 Offner Michael // Feb 15, 2013 at 11:05 AM
-1 from me
9 Simon Wright // Feb 24, 2013 at 1:37 AM
10 Michael Zock // Feb 24, 2013 at 11:00 AM
That way, the developer would be responsible for providing a boolean and you could re-use code from the "while" loop. More versatile than a plain counter and the resulting overhead should still be manageable.
11 Michael Offner // Feb 25, 2013 at 8:53 AM
my point is about consistency.
IF we do so, we have to do the same for other constructs as well.
<cfwhile condition="#c#" times="100">
while(c;100)
...
@Michael
if(myCondition)retry;
this would be only a convinience paramter like <cfdump abort>, i'm not a big fan to overload tags,functions statements with attributes,arguments parameters not directly related to the functionality. so i would prefer a "times" parameter, then this actually reduce the work for the programmer, a "condition" parameter not.
i will start a thread about this in the mailing list
Leave a Comment