| By Nik Molnar | Article Rating: |
|
| September 14, 2005 10:00 PM EDT | Reads: |
24,607 |
Since Adam's application is very complex, I have created a much smaller, simpler version of the problem, one you can look at, and, if so desire, easily implement in your own application.
This example randomly picks one of 10 phrases and reverses it. It's actually quite silly, much like all my bug jokes so far, but should give you a good idea of where I'm coming from.
Listing 1 shows the file the user will request. It's very straightforward and creates a small chain of function calls on line 4; it also instantiates the CFC shown in Listing 2.
Listing 2 is a component with two functions. The first, getPhrase(), will return a phrase based on the passed-in phraseNumber. If no phraseNumber is passed in, it will randomly pick a number. reversePhrase() asks getPhrase() for five random phrases and reverses and returns the fifth. The code of interest is the super.onCall() calls on lines 6 and 30, as well as the super.onResult() calls on lines 23 and 36. In this case "super" is a keyword that refers to Application.cfc (see Listing 3), since test.cfc extends Application.cfc (line 1, Listing 2).
Listing 3 is where the magic happens. When the user makes a request, based on the order of operations discussed before, the first bit of code ColdFusion processes is the onRequestStart() function. This creates an empty one-dimensional array called the cfcStack that will be accessed later in the request. Next index.cfm is run, which calls on my getPhrase() and reversePhrase() functions. Each of those functions call onCall() and onResult(), which log and stack what is going on in each function call. ColdFusion then processes the onRequestEnd() function, which checks to see if debugging is enabled and, if so, <cfdump>s the cfcStack.
This allows me to see each function that was called, in the order that it was called, what parameters it had to work with, and what results it returned. Notice the use of reserved functions described above onRequestStart() and onRequestEnd() as well as my own functions onCall() and onResult() within the Application.cfc.
I also added an onError() function, which in the case of an error would e-mail me the cfcStack as well as all the error information, and, if debugging is on, <cfrethrow> the error so I can see it immediately on the screen.
Just by taking a quick look at the cfcStack that is being dumped at the end of the request, I can tell if each function individually is behaving properly, as well as see if each one is fitting in with the parts of the whole request.
This simple <cfdump> is what led to this phone call: "Hey Adam, yeah, should be good to go. Alright man, thanks a lot. I hope you have a good weekend. Oh you're going there? Well have fun, and bring your bug spray; it can be pretty nasty this time of year."
Published September 14, 2005 Reads 24,607
Copyright © 2005 SYS-CON Media, Inc. — All Rights Reserved.
Syndicated stories and blog feeds, all rights reserved by the author.
More Stories By Nik Molnar
Nik Molnar is a ColdFusion/Flex developer with over seven years experience. He has led teams through the development of enterprise applications for the mortgage, sports ticketing, and stock industries. He is an amateur Iron Chef and posts regularly at his blog: foodDuo.com. He lives with his wife Katy and his dog Jacques in Orlando, Florida.
![]() |
Vijay Khambalkar 09/22/05 01:58:00 PM EDT | |||
Thanks for the great article! I am stuck with a problem in cfthrow and would appreciate your help. I did the onError handler. And want to throw another exception that will be caught in Flash. All the details are available at this stage, but cfthrow's message attribute does not take any variables. E.g. We want to use a variable in the message, otherwise there is no use of a common error handler. Could you please advise? TIA. :Vijay |
||||
![]() |
ColdFusion News Desk 09/14/05 10:10:35 PM EDT | |||
Macromedia ColdFusion Debugging - Don't Forget Your Bug Spray! 'Sorry about that Adam, we'll have to take a deeper look at it. Uh-huh. Yeah. No, I totally understand. Okay then, I'll give you a call if I still can't replicate the problem.' |
||||
- Adobe’s Aiming ColdFusion at Multiple Clouds
- Cloud Computing Journal: Adobe to Deliver ColdFusion in the Cloud
- Adobe May Cooperate with Apple to Transplant Flash Player to iPhone
- Adobe Flex Developer Earns $100K in New York City
- Adobe LiveCycle Enterprise Suite 2 for Cloud Computing
- Adobe Betas Target RIAs and Cloud Computing
- Adobe Cans Another 9% of its Workforce
- Moyea DVD4Web Converter V2.0 Converts DVD to FLV Fast and Synchronously with Watermarks
- Adobe Fiddles with its Web Apps
- Adobe & Salesforce Cut Cloud Deal
- Hosting.com Launches ColdFusion 9 in the Cloud
- The Real Time Infrastructure Ultimatum
- Adobe’s Aiming ColdFusion at Multiple Clouds
- Eval JavaScript in a Global Context
- Fig Leaf Software to Exhibit at Government IT Conference & Expo
- Cloud Computing Journal: Adobe to Deliver ColdFusion in the Cloud
- Is Microsoft as Free as Open Source?
- Adobe Reader Sued
- The Planet Named “Bronze Sponsor” of Cloud Computing Expo
- Microsoft Expression Web Has Got Game
- Adobe May Cooperate with Apple to Transplant Flash Player to iPhone
- Adobe Flex Developer Earns $100K in New York City
- Bruce Chizen Joins Voyager Capital as Venture Partner
- My Top Seven Wishes From Adobe MAX 2009
- The Next Programming Models, RIAs and Composite Applications
- Where Are RIA Technologies Headed in 2008?
- Constructing an Application with Flash Forms from the Ground Up
- AJAX World RIA Conference & Expo Kicks Off in New York City
- CFEclipse: The Developer's IDE, Eclipse For ColdFusion
- Personal Branding Checklist
- Adobe Flex 2: Advanced DataGrid
- Has the Technology Bounceback Begun?
- Building a Zip Code Proximity Search with ColdFusion
- i-Technology Viewpoint: We Need Not More Frameworks, But Better Programmers
- The Asynchronous CFML Gateway
- Web Services Using ColdFusion and Apache CXF





























