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.
About this entry
You’re currently hearting “Try/Catch Example,” an entry on I h♥rt actionscript.
- written:
- 06.16.09 / 11pm
- category:
- AS3

No comments
Jump to comment form | comments rss [?] | trackback uri [?]