From: Brian Candler Date: 2012-11-17T03:16:44+09:00 Subject: Re: Question on exceptions Robert Klemme wrote in post #1084722: > On Fri, Nov 16, 2012 at 9:27 AM, tamouse mailing lists > wrote: > >> Is this a good way to use exceptions? Having an insufficent balance >> might be something the user finds exceptional, but I'd think it would >> be a standard sort of handling for a bank applicaion... > > Depends on how you implement it: if you have the option to query the > current balance and define that a withraw operation is only allowed > with sufficient funds then you throw an exception. If OTOH you define > that withdraw will return success then you have a boolean return > value. Both approaches are legal and feasible. But I'd suggest *not* the current implementation: def withdraw( amount ) @balance -= amount if amount > 0 and amount <= @balance end There is no indication whether the withdrawal took place or not! -- Posted via http://www.ruby-forum.com/.