Try/Catch Example

So I’ve been thinking of a non-hacky way to use try/catch - and I finally found one (I think).

 
try
{
var classRef:Class      = getDefinitionByName($name) as Class;
}
catch(e:*)
{
trace(e)
}

Generally, getDefinitionByName just fails if a variable isn’t defined and you get this lame runtime error:

ReferenceError: Error #1065: Variable  is not defined.

 

I’m not a huge fan of that. I wanted to use getDefinitionByName as a staple for navigation (based on SWFAddress strings) - but I wanted to have a default handling if there wasn’t a class with that name. Now you can do that. Maybe this is still hacky - but me likey.

del.icio.us Slashdot Digg Facebook Technorati Google Yahoo


About this entry