Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8979319
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T19:49:27+00:00 2026-06-15T19:49:27+00:00

Sometimes I get this error, and I just want Rails to rescue/skip the error

  • 0

Sometimes I get this error, and I just want Rails to rescue/skip the error when it happens rather than stop the program completely. Is there a good way to do this?

Below is my code:

<% wiki = MediaWiki.new(:domain => 'commons.wikimedia.org') %>
<% wikimedia_user = wiki.find("File:Samuel_L_Jackson_as_Nick_Fury.jpg") %>

The second line causes this error:

NoMethodError (undefined method `first' for nil:NilClass)

If that happens, I just want wikimedia_user to be set to nil. I tried adding .inspect? to the end of the .find, but all I get is the error. Is there a way to do this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T19:49:28+00:00Added an answer on June 15, 2026 at 7:49 pm

    On the same line as the one you want to suppress the exception and return nil on, add rescue nil to the end.

    <% wikimedia_user = wiki.find("File:Samuel_L_Jackson_as_Nick_Fury.jpg") rescue nil %>
    

    Note: This isn’t generally considered a good practice, as any kind of exception thrown from that line will be caught by that rescue. In your case, it’s probably not a big problem, but something to keep in mind moving forward.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Sometimes users mistakenly redirected to ?Process=ViewImages&PAGEID=. When this happens, they get the following error.
I get this error sometimes reported when creating a dialog, i haven't experienced the
In Ruby on Rails, I sometimes get an error on the page as: compile
I get this error randomly, sometimes it shows and sometimes not! The Error: Now
I sometimes get this error when I run the JUnit tests. I'm not exactly
I have a program that segfaults from pointer arithmetic sometimes. I know this happens,
i am making ajax calls with jquery like this http://pastie.org/860837 and sometimes i get
When working with ActiveMQ in Eclipse, you might sometimes get a schema parsing error
sometimes i get an error like table is marked as corrupt and shld be
There are similar posts here. I just want to clarify something. I implemented this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.