I might be wrong, but I think hanlding an exception / error is not the expensive part.
The expensive part is throwing, as you said. But, if you have: var container:Sprite = null; container.addChild(child); The error will be thrown, whether you have a handler for it or not. The "cost" here is that the player has to unwind the stack looking for a suitable catch block to handle the error, jump to that block and then get back to where it was. In fact, I think handling the error right away should be less expensive than not catching it or catching it further down the stack. Cheers Juan Pablo Califano 2009/5/10 Mario Gonzalez <[email protected]> > One thing to note, is that try,catch(e:Error) is expensive for the AVM > because it has to Throw an error. > > Maybe not for this example or whatever you're creating, but it's something > to keep in mind for later. > I see a lot of code we receive riddled with that as a way of hiding > run-time errors AVM1 style. > > Just something to note, > > Mario Gonzalez > http://onedayitwillmake.com/ > http://wonderfl.kayac.com/user/onedayitwillmake/ > > ________________________________________ > From: [email protected] [ > [email protected]] On Behalf Of Paul Andrews [ > [email protected]] > Sent: Saturday, May 09, 2009 11:27 AM > To: Flash Coders List > Subject: Re: [Flashcoders] Try... catch...... > > I regret my one word answer because while it answers the question, there's > a > question of good practice to consider. > > Putting "return ball;" as the last line doesn't really help the casual > code > reader, because I need to really look hard at the code to realise that if > ball is not explicitly set elsewhere the return value will be null. > > However, > > catch (e:TypeError ){ return null; } > > explicitly shows that if the exception occurs the function will return > null. > > There's even a good argument for having "return null" at the end of the > code > too, since only one exception will explicitly return null... > > It's always better to have explicit code rather than try and save a > statement or two. We've all been down the "smart" code route though. Guilty > as charged. > > Paul > > > > > > ----- Original Message ----- > From: "Paul Andrews" <[email protected]> > To: "Flash Coders List" <[email protected]> > Sent: Saturday, May 09, 2009 4:17 PM > Subject: Re: [Flashcoders] Try... catch...... > > > > Yes. > > > > ----- Original Message ----- > > From: "ACE Flash" <[email protected]> > > To: "Flash Coders List" <[email protected]> > > Sent: Saturday, May 09, 2009 3:28 PM > > Subject: Re: [Flashcoders] Try... catch...... > > > > > >> Hi Hans, > >> > >> Thanks for the code :) I have one more question for the script below.... > >> > >> 1. if catch the TypeError, does the last line => return ball will > >> execute? > >> > >> Thanks a lot > >> > >> > >> public function myBall( value:int ):Ball > >> { > >> var ball:Ball = null; > >> > >> try{ > >> > >> //my code goes here..... > >> } catch (e:TypeError ){ > >> > >> } > >> return ball; > >> } > >> > >> > >> > >> On Sat, May 9, 2009 at 2:21 AM, Hans Wichman > >> <[email protected] > >>> wrote: > >> > >>> Hi, > >>> yup > >>> > >>> either > >>> public function myBall( value:int ):Ball > >>> { > >>> var ball:Ball > >>> > >>> try{ > >>> > >>> //my code goes here..... > >>> return ball; > >>> } catch (e:TypeError ){ > >>> trace("Whoops"); > >>> } > >>> return null; > >>> } > >>> > >>> or > >>> > >>> public function myBall( value:int ):Ball > >>> { > >>> var ball:Ball = null; > >>> > >>> try{ > >>> > >>> //my code goes here..... > >>> } catch (e:TypeError ){ > >>> > >>> } > >>> return ball; > >>> } > >>> There are more possibilities, some of which are better practice than > >>> others, > >>> but in such a small method, I wouldn't make to much of a fuss about it. > >>> > >>> regards, > >>> JC > >>> > >>> > >>> On Sat, May 9, 2009 at 3:22 AM, ACE Flash <[email protected]> wrote: > >>> > >>> > Hi there, > >>> > > >>> > I am trying to add try block in my code, how can I deal it with > return > >>> > function? > >>> > > >>> > If the code without any problems, I'd like to return "ball" , > >>> > otherwise > >>> I'd > >>> > like to EXIT or return null. > >>> > > >>> > Thanks > >>> > > >>> > ------------------------- > >>> > > >>> > public function myBall( value:int ):Ball > >>> > { > >>> > var ball:Ball > >>> > > >>> > try{ > >>> > > >>> > //my code goes here..... > >>> > return ball; > >>> > } catch (e:TypeError ){ > >>> > > >>> > } > >>> > > >>> > // shall I add => return null here? > >>> > } > >>> > _______________________________________________ > >>> > Flashcoders mailing list > >>> > [email protected] > >>> > http://chattyfig.figleaf.com/mailman/listinfo/flashcoders > >>> > > >>> _______________________________________________ > >>> Flashcoders mailing list > >>> [email protected] > >>> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders > >>> > >> _______________________________________________ > >> Flashcoders mailing list > >> [email protected] > >> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders > >> > > > > _______________________________________________ > Flashcoders mailing list > [email protected] > http://chattyfig.figleaf.com/mailman/listinfo/flashcoders > > _______________________________________________ > Flashcoders mailing list > [email protected] > http://chattyfig.figleaf.com/mailman/listinfo/flashcoders > _______________________________________________ Flashcoders mailing list [email protected] http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

