Conditional use of <cftry> ... <cfcatch>
I have been using the <cftry>…<cfcatch> methodology for over 5 years. It generally works very well. When there is a case where we need to trap an error and put out a friendly error message that works well also. When we need to know the actual problem, we have been commenting out the <cftry> … <cfcatch> mechanism and letting the CF detailed error message appear on the page. Since we are working on a test server, it doesn’t hurt anything to have the CF Robust error capability turned on. One would never do this on a production server, however.
We have recently decided that we do not want to continue to comment out these items because then the file dates get out of wack with the comment/note dates. There is a big push on, and rightly so, to keep these in synch so that we will know if folks are forgetting to note their changes at the top of the file.
So it occurred to me that if I could surround the <cftry> and <cfactch> with <cfif> statements, then I could make this a conditional thing and enable (include) and disable (hide) them at run-time by changing the setting of a Session varable.
Here is a simplified version of what I tried. I would set Session.UserRobustErrMsgs to false or true depending upon what I wanted the system to do. Normally is we be set to False: do not use robust error messages.
<cfif #Session.UseRobustErrMsgs# Is False>
<cftry>
</cfif>
Do something here….
<cfif #Session.UseRobustErrMsgs# Is False>
<cfcatch>
Do friendly error message here>
</cfcatch>
</cftry>
</cfif>
Note that there is nothing between the </cfcatch> and the </cftry>.
While it might have been a good idea, CF didn’t like it. CF threw the following error message:
The start tag must have a matching end tag. This could be because
<cfcatch> is not the last tag nested in the <cftry>. <cfcatch> must
Be the last tag insde a <cftry> tag.
If anyone knows of a conditional <cftry> … <cfcatch> technique/methodology, I would appreciate your shaping it with me.
Thank you in advance for your help.
:-}
Len
