[Prev][Next][Index][Thread]
Re: Exceptions help please!
On Mon, Sep 25, 2000 10:17 Uhr, Daniel Butun <mailto:dabutun@iinet.net.au>
wrote:
>I found this on a website and was hoping that someone could help me with
an
>exception for it.
>I've tried to work it out, but have been unable to identify it.
>The exception I'm after needs to catch invalid data like when a letter is
>used in the call to beer instead of a number.
>
>// Dylan version of 99 Bottles of Beer
>// programmer: Jim Studt jim@federated.com
>
>define method enumerate( count == 1 ) "1 bottle" end method enumerate;
>define method enumerate( count == 0 ) "no more bottles" end method
>enumerate;
>define method enumerate( count :: <integer> )
> format-to-string("%d bottles", count);
>end method enumerate;
>
>define method reference( count == 1) "it" end method reference;
>define method reference( count :: <integer>) "one" end method reference;
>
>define method beer (argv0, #rest noise)
> for ( i from argv0 to 1 by -1) // I have modified this to argv0 from
>99
> format( *standard-output*, "%s of beer on the wall, %s of beer.\n",
> enumerate(i), enumerate(i));
> format( *standard-output*,
> " Take %s down, pass it around, %s of beer on the wall.\n",
> reference(i), enumerate( i - 1));
> end for;
>end method beer;
>
>
>Thanks for your assistance
>Daniel Butun
>
Usually all errors can be caught by a "let handler <error>" construct and a
non-local exit.
This is what the block macro expands to.
So you can guard against errors with
block ()
// error generating statements...
exception(<error>)
// your (terminating) error handler goes here
end block;
Consult the DRM for more information at
http://www.gwydiondylan.org/drm/drm_114.htm#HEADING114-0
References: