Tuesday, January 26, 2010

Unexpected Action from ColdFusion Tag

Don't you hate it when things don't work the way you think they should? Especially when you check and recheck trying to find a problem only to find out that something is not doing what you think it should be doing.

I just had this experience. I was working hard on a website but part of the layout was turning out totally weird. Somehow a table was ending up enveloping more than it should. This came about because a ColdFusion tag was not doing what I thought it should be doing. Even re-reading the documentation it seems that it should be working like I thought it should.

Okay, the tag? CFTRY. Now maybe this is something that is already documented but I've never seen anything about the problem I ran into. Matter-of-fact the documentation says it should be working exactly as I think it should. But it doesn't.

The documentation says that you put code that may cause an error inside cftry tags then use cfcatch to deal with errors. So what does this tell us? That IF there is ANY error inside the cftry area then it will go to the cfcatch without processing anything. Not so.

Here is what I had
< cftry >
< table >
[call API ] [ parse results ] [ display results ]
< /table >
< cfcatch >
No Results
< /cfcatch >
< /cftry>

Now I look at that if the API call or the parsing results in an error this will fail into the cfcatch and show "No Results". Not so. After much messing with the borders etc to see what exactly was being displayed, I found that the table tag was actually being processed. So inside a cftry tag everything will be processed UNTIL it hits an error. This is NOT what the documentation leads you to believe. So of course I just had to move the table tag after the parsing function and it worked as I wanted it to. But I burned a WHOLE lot of time figuring that one out.

Labels: , , ,