i came from java world, and it is really big there. i don''t see a lot in ruby code samples. just a little. anybody out there using it? or is the errors just emailed to you? -- 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
When I started programming ruby I hardly ever used throw/rescue sequences, but the more I develop and the more complex the backend gets the more useful I find exceptions. Many things can be handled with inline IF statements which i think helps to eliminate the need for exceptions as much, but their are still places where its cleaner/ easier to throw an exception. On Dec 17, 5:07 pm, Philip Hallstrom <ra...-SUcgGwS4C16SUMMaM/qcSw@public.gmane.org> wrote:> > i came from java world, and it is really big there. > > i don''t see a lot in ruby code samples. just a little. > > > anybody out there using it? or is the errors just emailed > > to you? > > We use it all the time to catch things and work around it... > > You probably won''t see it in samples since samples tend not to include > much error handling... > > It''s there though... > > philip@MacBookPro:~/.../vendor/rails > $ grep -r "rescue" * | wc -l > 502 > > -philip--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
I use rescue excessively in my controller code. Even for something as simple as a show action: def show @thing = Thing.find(params[:id]) rescue ActiveRecord::RecordNotFound flash[:error] = "The thing you were looking for could not be found." redirect_to things_path end On Dec 18, 2007 8:24 AM, Andrew Bloom <akbloom-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > When I started programming ruby I hardly ever used throw/rescue > sequences, but the more I develop and the more complex the backend > gets the more useful I find exceptions. Many things can be handled > with inline IF statements which i think helps to eliminate the need > for exceptions as much, but their are still places where its cleaner/ > easier to throw an exception. > > On Dec 17, 5:07 pm, Philip Hallstrom <ra...-SUcgGwS4C16SUMMaM/qcSw@public.gmane.org> wrote: > > > i came from java world, and it is really big there. > > > i don''t see a lot in ruby code samples. just a little. > > > > > anybody out there using it? or is the errors just emailed > > > to you? > > > > We use it all the time to catch things and work around it... > > > > You probably won''t see it in samples since samples tend not to include > > much error handling... > > > > It''s there though... > > > > philip@MacBookPro:~/.../vendor/rails > > $ grep -r "rescue" * | wc -l > > 502 > > > > -philip > > >-- Ryan Bigg http://www.frozenplague.net --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
> i came from java world, and it is really big there. > i don''t see a lot in ruby code samples. just a little. > > anybody out there using it? or is the errors just emailed > to you?We use it all the time to catch things and work around it... You probably won''t see it in samples since samples tend not to include much error handling... It''s there though... philip@MacBookPro:~/.../vendor/rails $ grep -r "rescue" * | wc -l 502 -philip --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Ryan Bigg wrote:> I use rescue excessively in my controller code. Even for something as > simple > as a show action: > > def show > @thing = Thing.find(params[:id]) > rescue ActiveRecord::RecordNotFound > flash[:error] = "The thing you were looking for could not be found." > redirect_to things_path > end> -- > Ryan Bigg > http://www.frozenplague.netwell, dang nab. you don''t have a begin in that. is it required? or is it a rescue in a def, then the def is the begin of code block? i confused. -- 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Hi -- On Tue, 18 Dec 2007, gemblon (t.b.) wrote:> > Ryan Bigg wrote: >> I use rescue excessively in my controller code. Even for something as >> simple >> as a show action: >> >> def show >> @thing = Thing.find(params[:id]) >> rescue ActiveRecord::RecordNotFound >> flash[:error] = "The thing you were looking for could not be found." >> redirect_to things_path >> end > >> -- >> Ryan Bigg >> http://www.frozenplague.net > > well, dang nab. you don''t have a begin in that. is it required? > or is it a rescue in a def, then the def is the begin of code block?The def carries an implicit begin. David -- Training for 2008! Ruby on Rails training by David A. Black/Ruby Power and Light, LLC: * Intro to Rails, New York, NY, February 4-7 2008 * Advancing With Rails, New York, NY, February 11-14 2008 Hosted by Exceed Education. See http://www.rubypal.com for details! --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
David A. Black wrote:> Hi -- > > On Tue, 18 Dec 2007, gemblon (t.b.) wrote: > >>> redirect_to things_path >>> end >> >>> -- >>> Ryan Bigg >>> http://www.frozenplague.net >> >> well, dang nab. you don''t have a begin in that. is it required? >> or is it a rescue in a def, then the def is the begin of code block? > > The def carries an implicit begin. > > > David > > -- > Training for 2008! > Ruby on Rails training by David A. Black/Ruby Power and Light, LLC: > * Intro to Rails, New York, NY, February 4-7 2008 > * Advancing With Rails, New York, NY, February 11-14 2008 > Hosted by Exceed Education. See http://www.rubypal.com for details!As in other object oriented languages, Ruby offers a mechanism for exception handling. I When an exception occurs. Object of class Exception created. Raising Exception begin #processÂ… rescue #handle errors end We enclose the code that could raise an exception in a begin/end block and use rescue clauses to tell Ruby the types of exceptions we want to handle. Multiple Rescue Begin # Process rescue # handle error rescue # handle error end You can have multiple rescue clauses in a begin block, and each rescue clause can specify multiple exceptions to catch. hope this helps -- 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
You can also use ensure to make sure certain things happen, no matter if an exception is raised or not. On Dec 18, 2007 3:20 PM, Mohan Kumar <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > David A. Black wrote: > > Hi -- > > > > On Tue, 18 Dec 2007, gemblon (t.b.) wrote: > > > >>> redirect_to things_path > >>> end > >> > >>> -- > >>> Ryan Bigg > >>> http://www.frozenplague.net > >> > >> well, dang nab. you don''t have a begin in that. is it required? > >> or is it a rescue in a def, then the def is the begin of code block? > > > > The def carries an implicit begin. > > > > > > David > > > > -- > > Training for 2008! > > Ruby on Rails training by David A. Black/Ruby Power and Light, LLC: > > * Intro to Rails, New York, NY, February 4-7 2008 > > * Advancing With Rails, New York, NY, February 11-14 2008 > > Hosted by Exceed Education. See http://www.rubypal.com for details! > > As in other object oriented languages, Ruby offers a mechanism for > exception handling. I When an exception occurs. Object of class > Exception created. > > Raising Exception > > begin > #process… > rescue > #handle errors > end > We enclose the code that could raise an exception in a begin/end block > and use rescue clauses to > tell Ruby the types of exceptions we want to handle. > > Multiple Rescue > > Begin > # Process > rescue > # handle error > rescue > # handle error > end > > You can have multiple rescue clauses in a begin block, and each rescue > clause can specify multiple exceptions to catch. > > hope this helps > -- > Posted via http://www.ruby-forum.com/. > > > >-- Ryan Bigg http://www.frozenplague.net --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---