RE: [Flashcoders] Try... catch......
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: flashcoders-boun...@chattyfig.figleaf.com [flashcoders-boun...@chattyfig.figleaf.com] On Behalf Of Paul Andrews [p...@ipauland.com] 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 p...@ipauland.com To: Flash Coders List flashcoders@chattyfig.figleaf.com Sent: Saturday, May 09, 2009 4:17 PM Subject: Re: [Flashcoders] Try... catch.. Yes. - Original Message - From: ACE Flash acefl...@gmail.com To: Flash Coders List flashcoders@chattyfig.figleaf.com 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 j.c.wich...@objectpainters.com 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 acefl...@gmail.com 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 Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] Try... catch......
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 ma...@wddg.com 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: flashcoders-boun...@chattyfig.figleaf.com [ flashcoders-boun...@chattyfig.figleaf.com] On Behalf Of Paul Andrews [ p...@ipauland.com] 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 p...@ipauland.com To: Flash Coders List flashcoders@chattyfig.figleaf.com Sent: Saturday, May 09, 2009 4:17 PM Subject: Re: [Flashcoders] Try... catch.. Yes. - Original Message - From: ACE Flash acefl...@gmail.com To: Flash Coders List flashcoders@chattyfig.figleaf.com 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 j.c.wich...@objectpainters.com 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 acefl...@gmail.com 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 Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http
Re: [Flashcoders] Try... catch......
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 acefl...@gmail.com 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 Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
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 j.c.wich...@objectpainters.com 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 acefl...@gmail.com 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 Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] Try... catch......
Yes. - Original Message - From: ACE Flash acefl...@gmail.com To: Flash Coders List flashcoders@chattyfig.figleaf.com 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 j.c.wich...@objectpainters.com 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 acefl...@gmail.com 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 Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
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 p...@ipauland.com To: Flash Coders List flashcoders@chattyfig.figleaf.com Sent: Saturday, May 09, 2009 4:17 PM Subject: Re: [Flashcoders] Try... catch.. Yes. - Original Message - From: ACE Flash acefl...@gmail.com To: Flash Coders List flashcoders@chattyfig.figleaf.com 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 j.c.wich...@objectpainters.com 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 acefl...@gmail.com 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 Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
[Flashcoders] Try... catch......
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 Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] try-catch-finally ...
Sure. Reasonable good practice to catch exceptions. I normally use it for things like catch the exception and try it once again and if it fails for the second time. I will show an error message or try secondary option. Technically, it's good practice/professional to use try-catch-finally blocks in your actionscript logic. This ensures a robust, easily debugg-able application. However, can anyone comment if they actually use try-catch-finally or whether anyone is for or against it's use. I ask because I've received an application (which streams vidoe) that was blowing out numerous users CPUs to 100%. Upon further investigation, it appears that a netstream event is firing 20 times a second, and within the listener (listener function that is) for the event, there is a try-catch-finally block. I removed the try-catch-finally and CPU usage halved on my machine. Anyone care to comment for or against try-catch-finally and it's use. Steve. ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
[Flashcoders] try-catch-finally ...
Technically, it's good practice/professional to use try-catch-finally blocks in your actionscript logic. This ensures a robust, easily debugg-able application. However, can anyone comment if they actually use try-catch-finally or whether anyone is for or against it's use. I ask because I've received an application (which streams vidoe) that was blowing out numerous users CPUs to 100%. Upon further investigation, it appears that a netstream event is firing 20 times a second, and within the listener (listener function that is) for the event, there is a try-catch-finally block. I removed the try-catch-finally and CPU usage halved on my machine. Anyone care to comment for or against try-catch-finally and it's use. Steve. ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders