[ic] Usertag return value
Gert van der Spoel
gert at 3edge.com
Tue Feb 10 22:58:58 UTC 2009
> -----Original Message-----
> From: interchange-users-bounces at icdevgroup.org [mailto:interchange-
> users-bounces at icdevgroup.org] On Behalf Of Grant
> Sent: Wednesday, February 11, 2009 12:16 AM
> To: interchange-users at icdevgroup.org
> Subject: Re: [ic] Usertag return value
> >> > but that kills the whole page. What is the correct way to do this
> >> > so I can evaluate whether or not the tag executed properly?
> >> You could use exceptions with an Interchange [try] block (see
> >> etc/log_transaction for an example), but I think a simple return
> >> value would suffice in this case. If you want a "0" return value
> >> one or more of the sizes fails, then use a return value variable and
> >> only set it to true if all three succeed.
> > Hey,
> > Right, there's a bunch of ways to do this, depending on
> > whether you want to know which one failed (and exit immediately),
> > or you want to run all three anyway and just indicate the exit
> > status more as an information than an error.
> > If you want to exit immediately when one fails, use i.e.:
> > do_resize(....) or return 0;
> Is it a good practice to add "or return 0;" to the end of every
> command in a usertag? That way if something fails no further
> processing will take place.
Depends on if you care what gets returned. If you only want to make sure
that the usertag bails out at any point where a command doesn't return
something good then return 0 is fine ...
For debugging purposes probably not so great:
jumpthroughthehoop() or return 0;
vanishinthinair() or return 0;
If the usertag returns 0 you don't know if you got stuck in the hoop or the
air was not thin enough to vanish in (unless you add some logError stuff to
the jump & vanish subs, so you at least log where something failed).
And perhaps you want to inform the one who called the usertag directly why
it failed, so you can return something else:
jumpthroughthehoop() or return "The hoop was too small, time for a diet!";
vanishinthinair() or return "Hmmm I think Copperfield can do this a lot
> - Grant
> > (The above assumes do_resize() indicates success with non-zero value.
> > If it instead indicates failure with non-zero value, replace "or"
> > "and").
> > Another approach, if you want to run all three always, and just use
> > exit status as an information to see which one(s) failed:
> > $ret= 0;
> > do_resize1(...) or $ret+= 1;
> > do_resize2(...) or $ret+= 2;
> > do_resize3(...) or $ret+= 4;
> > return $ret;
> > So if the tag exits with 0, it worked. Otherwise, the exit
> > status will be a sum of all resizes that failed. I.e. if
> > exit value is 5, it means resizes 1 and 3 failed.
> > Cya,
> > -doc
> interchange-users mailing list
> interchange-users at icdevgroup.org
More information about the interchange-users