ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> rubyonrails-talk
rubyonrails-talk
[Rails] Re: Rails exception catching
by Bryan Duxbury other posts by this author
Aug 13 2007 2:20PM messages near this date
[Rails] Rails exception catching | [Rails] Re: Rails exception catching
Mike De wrote:
>  Hello I'm writting my first rails application and I would like to catch
>  when an id cant be found.
>  For instance  have create records 1 2 and 3
>  
>  I would like to:
>   records=Record.find(4)
>  and not get the error page rather somthing like
>  
>  records=Record.find(4)
>  
>  if (records==nil)
>  ...
>     do stuff
>  ...
>  else
>  ...
>     do other stuf
>  ...
>  end

Here's the thing: the reason that AR is throwing an exception when that 
fails is because you're specifically giving it an ID. The assumption is 
that you have an ID, you know the record exists, and therefore if it 
can't be found, it's an exceptional situation.

If the records attached to those IDs are going away for some reason, 
either you are stuck using a rescue, or perhaps you can refactor your 
problem so that you are making sure whatever dangling objects still have 
those ids are cleaned up before you actually try to find them.
-- 
Posted via http://www.ruby-forum.com/.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Ta
lk" group.
To post to this group, send email to rubyonrails-talk@[...].com
To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@[...].com
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
Thread:
Dehmlowm@gmail.com Mr
Bryan Duxbury
Mike De
Alex Wayne
Emilio Tagua

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved