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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T18:56:08+00:00 2026-05-22T18:56:08+00:00

In languages that have goto, I like to create an error block at the

  • 0

In languages that have goto, I like to create an error block at the end of a function (after return) and then when I do error checking within the function, I can just be concise and goto the error handler within each check. As I understand it, this is the one valid use of goto that isn’t considered bad practice.

Example in pseudocode:

 def example
   if (x) goto error
   do something
   if (y) goto error
   do something
   If (z) goto error
   do something
   return
  label 'error'
   log "error occurred"
   begin
     redirect_to :back
   rescue
     redirect_to root_url
   end
   return;
 end

As you can see, in this case, my error block is as long as the function itself, and repeating it 3 times would double the size of my code, and not be very DRY. However, it seems that Ruby doesn’t support goto, or at least if it does, as best as I can tell from looking on Google, it’s some sort of possibly joke library labeled evil.

Therefore, what are people doing in Ruby in order to handle repeated error checking where the same result should occur in each error?

  • 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-22T18:56:09+00:00Added an answer on May 22, 2026 at 6:56 pm

    Callbacks

    You should transfer many of these errors into your models, using Callbacks. These apply to errors that are relevant to actions that involve records in your database, i.e. checking whether a data input is appropriate.

    Filters

    Use before_filters and after_filters to check for errors, especially when you need to perform these checks on multiple controller actions. An example:

    before_filter :check_errors
    
    def example
       regular code...
    end
    
    private
      def check_errors
        error checking...
      end
    

    Case statements

    Use Case statements to improve your if statements, particularly when you have multiple checks involved.

    Prioritizing the above

    Use callbacks in your models whenever you can and definitely whenever data saving/updating/validation is involved.

    Use before_filters whenever the code is to be reused across multiple actions (and in my opinion, always whenever you have involved error checking like this).

    If you need these checks to occur only once, in this controller action alone, that do not involve records being changed, simply rewrite your code in a valid case statement (but my recommendation would still be to transfer to a before_filter).

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

Sidebar

Related Questions

I have read that most languages are becoming more and more like lisp, adopting
One of the huge benefits in languages that have some sort of reflection/introspecition is
We have always had languages that were preferable to be used in a particular
Typically languages have keywords that you are unable to use directly with the exact
So, I'm working under the assumption that we have typed languages because we make
The more and more advanced compilers, languages, and frameworks we have that either automate
I have a WordPress website that needs to have its articles in multiple languages.
Many languages have standard repositories where people donate useful libraries that they want others
I have several files that are in several different languages. I thought they were
I have a site that will ultimately support 4 languages and 2 countries (US

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.