Sai Babu
2011-May-05 06:20 UTC
How to placing common exceptions for all models in single method?
Hi guys,
In my models i am using common exception in every methods.
So Instead of writing same exception code on each method of model is
there a best way to separate exception code into seperate method.
when we need it simple we need to invoke that method.
for example like this
def rescue_excetpion
begin
rescue => e
raise "Error message is #{e}"
end
end
so when i invoke this rescue_excetpion method in my events method
it need to apply
def events
rescue_excetpion
@user = User.find(1)
end
Any one have idea about this ?
How to move all common exceptions into a single method ?
How to invoke that method?
Thanks in advance !!
--
Posted via http://www.ruby-forum.com/.
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
Frederick Cheung
2011-May-05 07:19 UTC
Re: How to placing common exceptions for all models in single method?
On 5 May 2011, at 07:20, Sai Babu <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Hi guys, > > In my models i am using common exception in every methods. > > So Instead of writing same exception code on each method of model is > there a best way to separate exception code into seperate method. > > when we need it simple we need to invoke that method. > >Sounds like your rescue_exception method should be yielding to a block, you can then do rescue_exception do ... end If you want to handle these exceptions at the controller level, you might want to look at rescue_from Fred> for example like this > > def rescue_excetpion > begin > > rescue => e > raise "Error message is #{e}" > > end > > end > > so when i invoke this rescue_excetpion method in my events method > > it need to apply > > def events > rescue_excetpion > @user = User.find(1) > end > > > Any one have idea about this ? > > How to move all common exceptions into a single method ? > > How to invoke that method? > > Thanks in advance !! > > -- > Posted via http://www.ruby-forum.com/. > > -- > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en. >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.