flex-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Justin Mclean <jus...@classsoftware.com>
Subject try/catch vs in
Date Fri, 03 Jan 2014 01:26:11 GMT
Hi,

While looking at some data grid code I noticed this:

            try
            {
                data = data[dataField];
            }
            catch(e:Error)
            {
                data = null;
            }

And I was curious to why try catch is used rather than this:

            if (dataField in data)
            {
                data = data[dataField];
            }
            else
            {
                data = null;
            }

I know "in" can be expensive but so is try catch. I've run each though scout and it looks
like the in operator is orders of magnitude faster and caused no garbage collection both when
the field exists and when it doesn't. Anyone have any insight/something to add?

Thanks,
Justin
Mime
View raw message