Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to include a structure as part of CFTHROW data?

Status
Not open for further replies.

lauridsd

MIS
Dec 13, 2000
7
0
0
US
As far as I can tell, there is no easy way to include a structure or other type of complex object as part of the details of a custom error using CFTHROW.

I am using the XMLValidate tag function to validate some XML content against an XSD.

But because the resulting structure does not automatically result in an application error if the validation STATUS = "no", I have to use CFTHROW to generate a custom error, but I would like to include the structure created by XMLValidate as part of the error detail, and I do not see a way to do it. I would prefer not to have to parse out the individual messages in the resulting "ERRORS" array and somehow send them with the CFTHROW, as there could be several messages, and re-formatting them in a manner that CFTHROW can accommodate seems a long way to go, especially when that whole structure is really what I want.

Does anyone know how to send a complex object (like the structure from XMLValidate) as part of the CFTHROW results?

I have researched the CFTHROW "Object" attribute, but it is as clear as mud.

Thanks in advance.
 
AFAIK, there is no simple way to include complex objects. The options I know of are either

a) create a string representation of the complex object and use one of the existing cfthrwo attributes or
b) create a custom java exception class.

As there are plenty of custom functions for converting structures to string format (xml, wddx, etcetera) I think that may be the simpler option.

I have researched the CFTHROW "Object" attribute, but it is as clear as mud.

It is intended to let you throw a java exception from CF. There are many exception classes, but most extend from java.lang.Exception:


Code:
<cfset obj = createObject("java", "java.lang.Exception").init("Exception thrown from CF")>
<cfthrow object="#obj#">

Most of the base exception classes do not allow for passing complex objects either. However, you could create your own custom class that does. Just compile it and add it to your CF class path. But that might be overkill here ..

----------------------------------
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top