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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T05:18:39+00:00 2026-05-18T05:18:39+00:00

In my last two projects I’ve seen the strange guideline, All Methods/Functions should return

  • 0

In my last two projects I’ve seen the strange guideline, “All Methods/Functions should return error-code using some common ERROR_CODE type”. In both projects ERROR_CODE is an int typedef.

Is there any good reason doing it in C++? Some MISRA requirement or something like that?

I can see only disadvantages:

  • If a function should return a value, it is done by argument reference. e.g.:

    string s;
    ERROR_CODE err = getString(s);

  • The importance of a function is not obvious. All looks the same. The list of errors conntains hundreds of errors from low level errors to some domain specific errors.

Have you experienced this programming style? Are there good arguments against it or for it?

  • 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-18T05:18:40+00:00Added an answer on May 18, 2026 at 5:18 am

    I think it’s a very bad style for several reasons.

    1. Like you’ve said, it forces you to pass pointers/references to store the actual result of a function.
    2. Like you’ve said, the unified error code is ugly because it’s trying to unify all sorts of errors from all sorts of domains.
    3. It creates an artificial dependency of all the program’s modules on the error code system, making it awkward to reuse a single module or small subset of modules in other programs.
    4. Further, since some of the error codes are domain-specific, it’s actually introducing dependencies between unrelated object types/modules, since they’re all dependent upon a component that’s dependent upon the union of all of their possible error types.

    My view is that any function/method which has more than a small manageable number of ways it can fail is either overly complex or poorly factored, probably both.

    If you really want to return error codes, I would swap things around and pass the pointer to the error code as an argument to the function, and make the actual result the return value. Then I would choose one of these two approaches for implementing the error codes:

    1. The simple way: throw away all abstraction of the error code and simply use int with a few universal error classes.
    2. The heavy object oriented way: Provide a pointer to an internal “error object” where the base class is very abstract and can be shared between all components without introducing any dependency, and where each component defines its own component-specific error objects if needed.

    A better approach if you’re using C++ would probably be using exceptions…

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

Sidebar

Related Questions

I've seen tbl_ prefixes decorating all tables in the last two code bases I've
In the last two days, ive run across code that has php echo'd variables
What is the problem with the last two statements in the code? #include <iostream>
I am using SimpleForm and Twitter Bootstrap in two Rails 3.2 projects. Unfortunately, my
At some point in the last month, two web application projects that I've been
I was playing with Google maps for last two days and started understanding little
How do I remove the last two chars from each line in a text
There is an example on php.net how to get last two domain segments in
While trying to execute the following lines only the last two statements are displayed(Here
I'm trying to figure out how to get only the last two files within

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.