PDA

View Full Version : How to silence runtime TypeError: Error #1009


maskedMan
05-22-2008, 01:21 AM
Hello there,

I'm running into a problem where I'm trying to silence a runtime error. Here's the bare bones of it:


class HasDictionary{
//only has this variable...
public var $list:Dictionary = new Dictionary();

//various functions...
}

import hasDictionary;
class anotherClass{

private var $myList:hasDictionary = new HasDictionary();

public function insertAfterID(index:*, item:*):Boolean{

try{

//error happens here when $myList.$list doesn't have a property === index;
var n:Object = $myList.$list[index];

}catch(e:Error){

trace("I don't care, just keep going");
return false;

}finally{

//do stuff with n
return true;

}

}
}


Thing is, I don't care if $myList.$list[index] exists or not. If it doesn't I just want the function to return false, but it isn't doing that. It's throwing an error and crashing the program. I just want the error to be silenced and for the program to continue on its merry way. try...catch...finally seems not to actually work for some reason, as it isn't catching the error. What am I doing wrong here?

evride
05-22-2008, 01:30 AM
i think could you just check if $myList.$list[index] exists using an if.

var n:Object;
if($myList.$list[index]){
n= $myList.$list[index];
}else {
n=false;
}



then create some action for if n==false

maskedMan
05-22-2008, 01:43 AM
Wow, thank you evdog! For some strange reason, this actually works. Do you know what's causing the problem with my version? Interestingly enough, I got the same error if I didn't have *any* sort of checking as when I used try...catch...finally. I had no built in checking to start with which is why I went with try.