Re: strong typing and error handling
- Posted by Pete Lomax <petelomax at blueyonder.co.uk> Jun 27, 2003
- 365 views
On Fri, 27 Jun 2003 18:56:33 +1000, Derek Parnell <ddparnell at bigpond.com> wrote: WOW, Derek you blew my fuse... > > >On Fri, 27 Jun 2003 07:55:08 +0000 (06/27/03 17:55:08) >, Peter Willems <peter at integratedmoves.com> wrote: > >> >> Maybe I'm shooting myself in the foot here, but.... >> >> One of the things in Eu that I really like is the rule-like >> variable typing that let us set boundaries for a variable. >> But it seems to me that the absense of an error-handler makes >> this close to useless because when I try to load a value into >> a variable that is outside it's boundaries, it exits the app >> with an error message. Thus I need to have my app check anyway >> when putting values into vars to prevent my app from exiting, >> so when I have to check var boundaries myself, what does the >> option to set boundaries when defining a var does for me ? >> >> Or do I mis something and IS it possible to capture boundary >> overflow (or underflow) in a simple way so I can write a simpe >> error-handler ? >> > >You can almost do this, so long as you don't mind not having access to = any=20 >meta-data. > > procedure logerr(sequence msg, object data) > printf(2, "Type Failure: %s\n", {msg}) > pretty_print(2, data, {3}) > end procedure > > global type Customer(object x) > > if not sequence(x) then > logerr("Customer Type must be a sequence.", x) > return 1 -- Return to app > end if > > if length(x) !=3D 5 then > logerr("Customer Type must have 5 fields.", x) > return 1 -- Return to app > end if > > ...etc... > > return 1 > end type > > >So long as you always return non-zero from a type definition, your=20 >application won't crash with a 'type' error. Yes, Got that. > >If you don't mind it crashing when an assignment is made you do this... > > sequence vTypeDefCrash > vTypeDefCrash =3D {0} > > procedure SetTypeDefCrash( object NewVal) > if sequence(NewVal) then > if length(vTypeDefCrash) > 1 then > vTypeDefCrash =3D vTypeDefCrash[2..length(vTypeDefCrash)] Help! > return > end if else > vTypeDefCrash =3D NewVal & vTypeDefCrash Ditto! > end if > end procedure > I want to understand here, but I don't > global type Customer(object x) > > if not sequence(x) then > logerr("Customer Type must be a sequence.", x) > return vTypeDefCrash[1] > end if > > if length(x) !=3D 5 then > logerr("Customer Type must have 5 fields.", x) > return vTypeDefCrash[1] > end if > > ...etc... > > return 1 > end type > So that by default it would crash except when you don't want it to = crash=20 >during a certain part of you code... > > SetTypeDefCrash(1) -- Turn on crash avoidance > . . . -- critical code > SetTypeDefCrash("") -- Restore it to whatever it was. > Are you trying to push() and pop() error handling status? >Unfortunately, you can't tell the user what line of code this was on, or= =20 >the name of the variable, or even what source file it was in. -- > >cheers, >Derek Parnell Pete