Alan Bullock
2006-Jun-30 21:47 UTC
[Rails] best practice: raise an exception or return false
just wondering how others deal with invalid/illegal operations on their models? until now, I''ve simply been returning true or false depending on wether or not the operation succeeded, but that doesn''t tell the calling function why the operation failed (if it failed). I could use custom exceptions, but is it good practice to raise an exception on every invalid action or just the more serious ones? where''s the best place to store custom exceptions? I''m thinking model specific ones in the model file itself and generic ones in environment.rb...? how do others deal with this? alan
Tom Mornini
2006-Jun-30 23:48 UTC
[Rails] best practice: raise an exception or return false
Raise exceptions. They''re much harder miss. :-) -- -- Tom Mornini On Jun 30, 2006, at 2:46 PM, Alan Bullock wrote:> just wondering how others deal with invalid/illegal operations on > their > models? > > until now, I''ve simply been returning true or false depending on > wether or > not the operation succeeded, but that doesn''t tell the calling > function why > the operation failed (if it failed). > > I could use custom exceptions, but is it good practice to raise an > exception > on every invalid action or just the more serious ones? where''s the > best > place to store custom exceptions? I''m thinking model specific ones > in the > model file itself and generic ones in environment.rb...? > > how do others deal with this?
Brian Hogan
2006-Jul-01 00:00 UTC
[Rails] best practice: raise an exception or return false
+1 for exceptions. It forces you to handle the errors. On 6/30/06, Tom Mornini <tmornini@infomania.com> wrote:> > Raise exceptions. They''re much harder miss. :-) > > -- > -- Tom Mornini > > On Jun 30, 2006, at 2:46 PM, Alan Bullock wrote: > > > just wondering how others deal with invalid/illegal operations on > > their > > models? > > > > until now, I''ve simply been returning true or false depending on > > wether or > > not the operation succeeded, but that doesn''t tell the calling > > function why > > the operation failed (if it failed). > > > > I could use custom exceptions, but is it good practice to raise an > > exception > > on every invalid action or just the more serious ones? where''s the > > best > > place to store custom exceptions? I''m thinking model specific ones > > in the > > model file itself and generic ones in environment.rb...? > > > > how do others deal with this? > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060701/e4a5da16/attachment.html