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

Reply via email to