From: Alan Chen Date: 2002-02-12T05:01:04+09:00 Subject: Re: rescue syntax On Tue, Feb 12, 2002 at 04:11:42AM +0900, Dave Thomas wrote: > Alan Chen writes: > > > For methods, I'd imagine something like the following > > > > def method > > # method logic > > rescue > > # oops, bad logic > > end > > Shazzaam! And so it shall be. :) > > Ruby supports this articular syntax already. > > It also has a per-statement rescue: > > # convert str to an integer if possible, otherwise set > # it to -1 > a = (Integer(str) rescue -1) > > > (the parentheses are needed here) > > > Cheers > > Dave Well, I feel a little stupid. :) Thanks for pointing this out. I guess I missed that in my copy of Programming Ruby. How would I go about using the per-statement using an if statement? Or with more complex rescue logic. For example something like my first example? if( expr ) begin # do stuff rescue # rescue logic end end I've tried a couple of different interations and haven't quite hit upon the right syntax. -- lan -- Alan Chen Digikata LLC http://digikata.com