[DGD] Fw: Re: callout cantrip

bart at wotf.org bart at wotf.org
Wed Mar 18 12:26:22 CET 2009


To detail this some further:

/* /wiz/aidil/obj/testobj.c */

int divint(int a, int b) {
  return a/b;
}

atomic int test() {
  int ret;
  catch {
    ret = divint(4,0);
  } : {
    write(caught_error(1));
  }
  return ret;
}

>  eval return find_object("/wiz/aidil/obj/testobj")->test();
[CAUGHT] Division by zero
Object: /std/user#62, program: /std/user, line 187
 187 receive_message   /std/user (#62)
 182 _receive_message  /std/user (#62)
 675 receive_message   /std/player (#79)
  23 main              /cmds/wiz/eval
  10 exec              /tmp/aidil
   8 test              /wiz/aidil/obj/testobj
   2 divint            /wiz/aidil/obj/testobj
Result:
0

This works because the caught error doesn't cancel the atomic transaction.
Obviously, if you'd error() there in the part after the catch, the transaction
will be canceled. In that case the only way to get this info to survive is to
pass it as argument to error()

Bart.

On Tue, 17 Mar 2009 17:57:34 -0700, Shentino wrote
> Indeed,
> 
> bart, how do you transmit information past the atomic event horizon?
> 
> On Tue, Mar 17, 2009 at 5:53 PM, Noah Gibbs <noah_gibbs at yahoo.com> wrote:
> 
> >
> >  That's a really good idea!  Definitely cleaner than the Phantasmal method
> > of re-throwing.
> >
> >  I don't know the scope of TLS vars relative to atomic functions -- can
> > this be used to get a function trace out of an atomic error?  Phantasmal
> > encodes it in the error string itself, but that can run afoul of string
> > length issues.
> >
> > --- On Tue, 3/17/09, bart at wotf.org <bart at wotf.org> wrote:
> >
> > > From: bart at wotf.org <bart at wotf.org>
> > > Subject: Re: [DGD] Fw: Re: callout cantrip
> > > To: "All about Dworkin's Game Driver" <dgd at dworkin.nl>
> > > Date: Tuesday, March 17, 2009, 5:24 PM
> > > Well, that idea seems to work quite well..
> > >
> > > a=2;
> > > b=0;
> > > catch {
> > >   return a/b;
> > > } : {
> > >   write(caught_error(1));
> > > }
> > >
> > >
> > > when called causes:
> > >
> > > [CAUGHT] Division by zero
> > > Object: /std/user#62, program: /std/user, line 187
> > >  187 receive_message   /std/user (#62)
> > >  182 _receive_message  /std/user (#62)
> > >  675 receive_message   /std/player (#79)
> > >   23 main              /cmds/wiz/eval
> > >   10 exec              /tmp/aidil
> > >
> > > Code is in the latest gurbalib distribution and in
> > > subversion of course.
> > >
> > > On Sat, 14 Mar 2009 16:02:48 +0100, bart wrote
> > > > Talking about such 'tricks', I've been
> > > pondering saving a copy of the
> > > > call_stack or an 'interpreted version' of it
> > > in a tls var when
> > > > encountering a caught runtime error so one can rethrow
> > > it and
> > > > provide a proper trace of the caught error.
> > > >
> > > > Bart.
> > >
> > > --
> > > Created with Open WebMail at http://www.bartsplace.net/
> > > Read my weblog at http://soapbox.bartsplace.net/
> > >
> > > ___________________________________________
> > > https://mail.dworkin.nl/mailman/listinfo/dgd
> >
> >
> >
> > ___________________________________________
> > https://mail.dworkin.nl/mailman/listinfo/dgd
> >
> ___________________________________________
> https://mail.dworkin.nl/mailman/listinfo/dgd


--
Created with Open WebMail at http://www.bartsplace.net/
Read my weblog at http://soapbox.bartsplace.net/




More information about the DGD mailing list