Forum: Ruby RecordNotFound

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Ba0976f0b91128a01af8c58d80b523ae?d=identicon&s=25 Franz Bettag (Guest)
on 2006-03-16 13:25
(Received via mailing list)
Hi guys,

uhm how to fetch out a RecordNotFound?

i have this here

@new_ipv4 = Ipv4addr.find(IPAddr.new(params[:ipv4addr][:id]).to_i)

but at this line it gives an error RecordNotFound. But this is okay! But
now i want the application to do something special like adding the not
found IPaddr to the database.. But how? since it stops at this line =)

Thanks in advance!
--


Mit freundlichen
Grüßen
Franz Bettag

____________________________
QS Housing
Franz Bettag
Ludwigstr. 45-47
90402 Nürnberg
http://www.qs-housing.net

Tel: +49 1805 737376 664
Fax: +49 1805 737376 665
2c80e1b0837eec76d38d4f7fa1c15e87?d=identicon&s=25 Michael Gorsuch (Guest)
on 2006-03-16 13:34
(Received via mailing list)
Try using Ruby's exception handling:

begin
  @new_ipv4 = Ipv4addr.find(IPAddr.new(params[:ipv4addr][:id]).to_i)
rescue
  # Code to add data to database
end

A little more info:

http://www.rubycentral.com/book/tut_exceptions.html
Ba0976f0b91128a01af8c58d80b523ae?d=identicon&s=25 Franz Bettag (Guest)
on 2006-03-16 13:40
(Received via mailing list)
aaah! Thanks a lot!

Michael Gorsuch schrieb:
> http://www.rubycentral.com/book/tut_exceptions.html
>>
>>
>>
>
>


--


Mit freundlichen
Grüßen
Franz Bettag

____________________________
QS Housing
Franz Bettag
Ludwigstr. 45-47
90402 Nürnberg
http://www.qs-housing.net

Tel: +49 1805 737376 664
Fax: +49 1805 737376 665
4299e35bacef054df40583da2d51edea?d=identicon&s=25 James Gray (bbazzarrakk)
on 2006-03-16 15:01
(Received via mailing list)
On Mar 16, 2006, at 6:33 AM, Michael Gorsuch wrote:

> Try using Ruby's exception handling:
>
> begin
>   @new_ipv4 = Ipv4addr.find(IPAddr.new(params[:ipv4addr][:id]).to_i)
> rescue

The above line would be better as:

rescue ActiveRecord::RecordNotFound

That way it doesn't hide errors we weren't expecting.

>   # Code to add data to database
> end

James Edward Gray II
This topic is locked and can not be replied to.