Since it's impossible for a given thread to be handling more than one
exception at a time, you can cheat the system a little using a request
variable. Reserve request.exceptionInfo or whatever for exception
information, and then write a custom throw tag that accepts and
object, stores it in that request variable, and then generates a
standard CF exception with the name of the object as the type. Then
catch that type as you see fit, and write a custom catch tag that
accepts a 'name' attribute, and uses it to set the object to that name
(so you have a reference to the 'exception' object).
example.cfm:
<cfimport prefix="ex" taglib="/tags/exception" />
<cftry>
<ex:throw object="#createObject('component',
'my.custom.exception').init('test exception')#" />
<cfcatch type="my.custom.exception">
<ex:catch name="e" />
<cfoutput>An exception was caught: #e.getMessage()#</cfoutput>
</cfcatch>
</cfcatch>
thow.cfm:
<cfset request.exceptionObject = attribute.object />
<cfthrow type="#some.magic.expression.using.metadata#" />
catch.cfm:
<cfset caller[attributes.name] = request.exceptionObject />
I'll grant you it's not amazingly elegant, but it works very well,
particularly with throwing validation exceptions from your business
layer to your UI, because you can package all the errors for a given
object into one exception.
cheers,
barneyb
On 5/15/05, Roland Collins <[EMAIL PROTECTED]> wrote:
>
>
>
> <cfset myException = CreateObject("component"
> "cfc.CustomValidationException").init("An error occurred
> while validating the data.")>
>
> <cfset myException.addInvalidData(someBadInfo)>
>
> <cfset myException.addInvalidData(moreBadInfo)>
>
> <cfset myException.addInvalidData(someWorseInfo)>
>
>
>
>
>
> <cfthrow exception="myException">
>
>
>
> While it's not at the top of my list, I too think it would be a nice
> feature. I hate having to encode data in strings and lists.
>
>
>
> Roland
--
Barney Boisvert
[EMAIL PROTECTED]
360.319.6145
http://www.barneyb.com/
Got Gmail? I have 50 invites.
----------------------------------------------------------
You are subscribed to cfcdev. To unsubscribe, send an email to
[email protected] with the words 'unsubscribe cfcdev' as the subject of the
email.
CFCDev is run by CFCZone (www.cfczone.org) and supported by CFXHosting
(www.cfxhosting.com).
CFCDev is supported by New Atlanta, makers of BlueDragon
http://www.newatlanta.com/products/bluedragon/index.cfm
An archive of the CFCDev list is available at
www.mail-archive.com/[email protected]