It's not just about state, the schema suggested below would not work if the
exception fuseaction in turn caused another exception to be thrown since it
is not inside a CFTRY CFCATCH block any more (Lee - an example of abstract
thinking for webmaster :-)
For similar reasons I would not recommend using CFLOCATION, as it may (and
has ;-) throw you into an infinite loop of redirection in cases of extreme
error situations like a crashed DB server.
My take on it, is: reset the generated output as it is sure to have some
half baked junk, then perform error logging etc. then display a friendly
error message with links back to relevant sections of the application.
This should be bullet proof except for CFML code syntax errors which are not
passed as exceptions and cause an ugly CF parser error message.
Cheers,
Noam
P.S. here's an example for code lovers:
<CFTRY>
<cf_bodycontent>
<cfswitch expression="#attributes.fuseaction#">
<cfcase value="Index">
...
</cfcase>
...
</CFswitch>
</cf_bodycontent>
<CFCATCH TYPE="Any">
<cfcontent type="text/html" Reset="Yes">
<!--- Display friendly error message with some debug info instead of
ugly CF crash --->
<CFINCLUDE template="act_Error.cfm">
<cfset Attributes.Title2 = "Error Handler">
<cf_bodycontent>
<cfinclude template="dsp/dsp_Error.cfm">
</cf_bodycontent>
</CFCATCH>
</CFTRY>
<cfinclude template="app_layout.cfm">
The additional request is a drag to be sure, but if you need to
retain any
attribute settings, pass them through in the url_ redirector. The
url_ file
is still the best way to preserve your "root" circuit so that you
can easily
move from circuit to circuit.
Besides...in a stateless environment can you really "lose" state?
(that's a
joke)
-----Original Message-----
From: Patrick McElhaney [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, January 09, 2001 12:03 PM
To: Fusebox
Subject: Taking the fuses out of the fusebox.
Has anyone ever tried taking the cfswitch
statement and putting it in a seperate file,
so that we can change the fuseaction without
using <cflocation>? (The point is that by
redirecting we lose state, and waste time
with an additional request.)
INDEX.CFM
---------
..... standard fusebox stuff ...
<cftry>
<!---
If something goes wrong in a fuse,
attributes.fuseaction will be changed
and an exception will be thrown.
--->
<cfinclude template="fuseactions.cfm">
<cfcatch type="any">
<cfinclude template="fuseactions.cfm">
</cfcatch>
</cftry>
FUSEACTIONS.CFM
---------------
<cfswitch expression="#attributes.fuseaction#">
<cfcase value="addform">
<cfinclude template="dsp_form.cfm">
</cfcase>
<cfcase value="editform">
<cfinclude template="qry_data.cfm">
<cfinclude template="dsp_form.cfm">
</cfcase>
<cfcase value="insert">
<cfinclude template="act_insert.cfm">
<cfinclude template="dsp_view.cfm">
</cfcase>
<cfcase value="update">
<cfinclude template="act_update.cfm">
<cfinclude template="dsp_view.cfm">
</cfcase>
<cfdefaultcase>
<cfset attributes.fuseaction="addform">
</cfdefaultcase>
</cfswitch>
Patrick
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Structure your ColdFusion code with Fusebox. Get the official book at
http://www.fusionauthority.com/bkinfo.cfm
Archives: http://www.mail-archive.com/[email protected]/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists