RE: [flexcoders] hasEventListener() on null object causes silent failure and exit from block
Yeah, binding can interfere with debugging. I'm sure you already know this, but for newbies reading this thread... An exception throws an error which leaves the method immediately and goes up the stack frame until caught, or until it gets to the top where the debugger player will show an exceptions dialog and the release player will simply not execute any more code and let the renderer take a pass at drawing the display list. The idea behind throwing errors is to not have to build in code to gracefully work your way up the call stack when something bad happens. That kind of coding is tricky and requires that virtually every method return a value. The recommended pattern, which is required in most strongly-typed languages is if (someObj && someObj.someFoo) Try/catch blocks are more expensive than an additional null check per if statement. Bracketing entire methods in try/catch is not recommended. -Alex From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On Behalf Of Ben Clinkinbeard Sent: Wednesday, April 02, 2008 9:58 AM To: flexcoders@yahoogroups.com Subject: Re: [flexcoders] hasEventListener() on null object causes silent failure and exit from block Ah, yes, binding was involved. I still don't understand why the whole block exits though. Err, I guess I understand, but I don't like it. :) I have always wished the null checks worked a bit differently. Like it would be handy if we could say if( someObj.hasFoo ) and it would just evaluate to false if someObj was null. Oh well, a boy can dream... Thanks Alex. Ben On Wed, Apr 2, 2008 at 12:53 PM, Alex Harui <[EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]> > wrote: I get the RTE when I call greatFun(). Are you sure that wasn't part of a binding expression evaluation? Those have catch blocks. From: flexcoders@yahoogroups.com <mailto:flexcoders@yahoogroups.com> [mailto:flexcoders@yahoogroups.com <mailto:flexcoders@yahoogroups.com> ] On Behalf Of ben.clinkinbeard Sent: Wednesday, April 02, 2008 7:25 AM To: flexcoders@yahoogroups.com <mailto:flexcoders@yahoogroups.com> Subject: [flexcoders] hasEventListener() on null object causes silent failure and exit from block This seems like a bug to me. In the following code if dp is null, the trace will not be executed. function greatFun():void { if( dp.hasEventListener( "foo" ) ) { // do stuff } trace( "WTF" ); } It should either throw a RTE or just evaluate to false, shouldn't it? Thanks, Ben
Re: [flexcoders] hasEventListener() on null object causes silent failure and exit from block
Ah, yes, binding was involved. I still don't understand why the whole block exits though. Err, I guess I understand, but I don't like it. :) I have always wished the null checks worked a bit differently. Like it would be handy if we could say if( someObj.hasFoo ) and it would just evaluate to false if someObj was null. Oh well, a boy can dream... Thanks Alex. Ben On Wed, Apr 2, 2008 at 12:53 PM, Alex Harui <[EMAIL PROTECTED]> wrote: >I get the RTE when I call greatFun(). Are you sure that wasn't part of > a binding expression evaluation? Those have catch blocks. > > > -- > > *From:* flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] *On > Behalf Of *ben.clinkinbeard > *Sent:* Wednesday, April 02, 2008 7:25 AM > *To:* flexcoders@yahoogroups.com > *Subject:* [flexcoders] hasEventListener() on null object causes silent > failure and exit from block > > > > This seems like a bug to me. In the following code if dp is null, the > trace will not be executed. > > function greatFun():void > { > if( dp.hasEventListener( "foo" ) ) > { > // do stuff > } > trace( "WTF" ); > } > > It should either throw a RTE or just evaluate to false, shouldn't it? > > Thanks, > Ben > > >
RE: [flexcoders] hasEventListener() on null object causes silent failure and exit from block
I get the RTE when I call greatFun(). Are you sure that wasn't part of a binding expression evaluation? Those have catch blocks. From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On Behalf Of ben.clinkinbeard Sent: Wednesday, April 02, 2008 7:25 AM To: flexcoders@yahoogroups.com Subject: [flexcoders] hasEventListener() on null object causes silent failure and exit from block This seems like a bug to me. In the following code if dp is null, the trace will not be executed. function greatFun():void { if( dp.hasEventListener( "foo" ) ) { // do stuff } trace( "WTF" ); } It should either throw a RTE or just evaluate to false, shouldn't it? Thanks, Ben
[flexcoders] hasEventListener() on null object causes silent failure and exit from block
This seems like a bug to me. In the following code if dp is null, the trace will not be executed. function greatFun():void { if( dp.hasEventListener( "foo" ) ) { // do stuff } trace( "WTF" ); } It should either throw a RTE or just evaluate to false, shouldn't it? Thanks, Ben