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 3997328
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T07:23:18+00:00 2026-05-20T07:23:18+00:00

According to save bang your head, active record will drive you mad , we

  • 0

According to save bang your head, active record will drive you mad, we should avoid using save! and rescue idiom for exceptional situations. Given that, say a model needs to @post.mark_rejected.

If the code in mark_rejected fails due to one of the below problems, should an exception be thrown? :

  • if there is a validation problem
  • if a non-nullable-field was being assigned a null
  • if there was a connection loss to database

If we do not throw an exception, then:

  • controller action would have to check for return value of mark_rejected and do it’s thing
  • we are not expecting an exception from that method call, so we do not write a rescue clause in the controller action, thus the exception bubbles up to (..wherever..) and will probably show up as some (500 HTTP?) error

Example code:

def mark_rejected
  ...
  save!
end

or

def mark_rejected
  ...
  save
end
  • 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-05-20T07:23:18+00:00Added an answer on May 20, 2026 at 7:23 am

    There’s more overhead in an exception, so there is a performance issue, especially when it can be expected that it will likely be thrown often, as is the case with save.

    It is fewer lines of code to check if the return value is false than rescue an exception, so I don’t see how it’s a problem having to check for the return value if you already have to rescue the exception. How often would an exception thrown by save! ever have to bubble-up the call stack in practice? Rarely, if ever, in my experience.

    If there is an exception thrown when calling save as opposed to save! you should want it to show a 500 error page because that’s what happened: an unrecoverable, unknown, unexpected internal server error.

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

Sidebar

Related Questions

according to this image, i try to save data in NSUserDefaults but my App
According to the manual , git dcommit will create a revision in SVN for
I want to save my objects according to a key in the attributes of
According to the .NET Framework General Reference: Error Raising and Handling Guidelines exceptions should
I'm using writeImageToSavedPhotosAlbum:metadata:completionBlock: to save images to the camera roll (GPS data is in
What is the best way to save a file to my SQL database using
I have a problem while trying to save cookies to a file using FileCookieJar
I have developed a TCP server according to your advises: High performance TCP server
I want create constructor that will take one or more integers and save it
I am looking for a way to save or update records, according to the

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.