[LRUG] [Chat] IronRuby
pratik at thinkwares.com
Tue Jul 24 07:35:51 PDT 2007
Agree. That was just a silly example. But to achieve what you said,
you should basically define exceptions in appropriate namespaces to
reflect the behavior. In my example, if he's not there - the exception
should have been raised at much higher level than "Something".
On 7/24/07, Paul Doerwald <paul at liquidmedia.ca> wrote:
> I've always thought that you should use exceptions for "exceptional"
> cases. In the normal or alternate cases, the exception won't happen.
> Save, for instance, has a normal case, save the record, and an
> alternate case, there is a validation problem that has caused us to
> be unable to save the record. You could argue a third "exceptional"
> case, which would be that the database (due to constraints or out-of-
> disk-space, or some other db-specific problem) has caused the system
> to be unable to save the record even though the validations have
> passed. (This is not supported because DHH/ActiveRecord doesn't
> believe that databases are anything more than a persistent storage).
> In the example you showed in pastie, by the looks of it, those are
> all alternate cases, not exceptional ones. Exceptional would be if
> you try to kick, pamper or kill him, and he's not there.
> On 24-Jul-07, at 10:13 AM, Pratik Naik wrote:
> > It's not about one way being better than the other. It just reflects
> > how you persue things. When you take rescue approach, your main code
> > is only the perfect use case, instead of handling "things that could
> > go wrong" in the same block.
> > I believe it also helps you keep the logic seperate for perfect use of
> > an API and when someone screws up.
> > We all know the difference between save and save! So that example is
> > not very helpful.
> > But imagine something like http://pastie.caboo.se/81719
> > I'm not saying it's a better way. I'm just saying that it's not a
> > wrong way either.
> >> Why is that better than
> >> def create
> >> @person = Person.new(params[:person])
> >> if @person.save
> >> redirect_to :index
> >> else
> >> render :action => "new"
> >> end
> >> end
> >> ?
> >> --
> >> * J *
> >> ~
> >> _______________________________________________
> >> Chat mailing list
> >> Chat at lists.lrug.org
> >> http://lists.lrug.org/listinfo.cgi/chat-lrug.org
> > _______________________________________________
> > Chat mailing list
> > Chat at lists.lrug.org
> > http://lists.lrug.org/listinfo.cgi/chat-lrug.org
> Chat mailing list
> Chat at lists.lrug.org
More information about the Chat