Programming, Technology, Web Development, Whatever
Posts tagged error
CRUD problem in IE6 with cfajaxproxy
Aug 9th
When using the CFC generator in Coldfusion Builder to create a DAO for a database table, Coldfusion will create four functions
within this file, namely create, read, update, and delete. When creating a Javascript object out of the CFC using cfajaxproxy, Coldfusion will populate your document with Javascript that contains the names of these functions in the document. This will break IE6.
Typically this wouldn’t be a problem, however the trouble arises when the document is populated with the last function: delete. Whereas Coldfusion sees delete as a function within the CFC, however delete in Javascript is a reserved word to deallocate dynamically allocated memory. All other browsers (including IE7+) recognizes that delete is indeed a function of your CFC, however IE6 simply recognizes it as a reserved word, and discontinues parsing the pages Javascript, resulting in Object Expected errors when other Javascript code is executed. To get around this, you simply need to rename the delete function in the CFC to something different.
Attached Files:
Intro to Try/Catch in Flex/Actionscript
Jan 15th
Sometimes when you’re making a Flex application, you’ll expect a certain piece of code to fail at some point. This is the job of try and catch. For example, say I wanted to loop over a bunch of components I had within an HBox:
<mx:HBox id="myHBox"> <mx:Panel title="1"/> <mx:Panel title="2"/> <mx:Panel title="3"/> <mx:Panel title="4"/> <mx:Panel title="5"/> <mx:Panel title="6"/> <mx:Panel title="7"/> </mx:HBox>
To loop over these panels without setting a specific id for each, we can use the DisplayObject‘s getChildAt() function. So within the
private function averageTitles(box:HBox):Number
{
// initialize some variables
var tempTotal:int = 0;
var i:int = 0;
var length:int = 0;
var isEnd:Boolean = false;
var tempPanel:Panel;
//loop until the isEnd variable is true
while(!isEnd)
{
//Try to get the child at location i
try
{
tempPanel = box.getChildAt(i);
tempTotal += parseInt(tempPanel.title);
i++;
}
//if it fails, we have reached the end of the panels
catch(e:Error)
{
isEnd = true;
}
//we always want to increase the length,
//since the length is longer than the index
finally
{
length++;
}
}
//return the average
return tempTotal / length;
}
(Obviously the length is unnecessary, Its just an example)
The try block is what the program will attempt to execute first, and the code you expect to fail. In this example, the myHBox.getChildAt(i) is undoubtedly going to fail at some point when the HBox runs out of panels. When this happens, the program will throw an error, more specifically a RangeError, meaning you’re attempting to access something outside the array’s bounds. The catch block will quite literally “catch” the error before it escapes to the main application and causes a runtime error(the window that pops up when something goes wrong in a flash movie in your browser). The catch block will then execute the code within its block. A catch block can catch many kinds of errors; in my example I use the error type Error, meaning it will catch all errors. Since I know what kind of error will occur in my code, I could have just as easily written:
catch(e:RangeError)
{
isEnd = true;
}
And the effect would be the same. You can also catch multiple types of errors within a try block using multiple catch statements where appropriate.
For a list of all types of errors, look at the Subclasses of the Error class in the Adobe Flex Language Reference.
You may also have noticed the finally block which increments the var length. The finally block is used to execute code regardless of when an error happens. So in the finally block in my code:
finally
{
length++;
}
The length will always be incremented if there is an error or not, as we need the total number of items to find the average.
That’s basically it, I’ll write a more advanced tutorial later on things like throwing new errors and such. Good luck in your coding endeavors.