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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T20:12:32+00:00 2026-05-11T20:12:32+00:00

In the process of creating a module I am facing a dilemma: should each

  • 0

In the process of creating a module I am facing a dilemma: should each class internally define its own error codes, or should there be a module-wide error codes defined?

So far pros and cons go hand-in-hand, but I am inclined to define per-class errors:

1:

class MyClass
{
public:       
   typedef enum _TResult {
       EOk = 0,
       EErrNoMemory,
       EErrBadParam,
       <...>
   } TResult;

   TResult DoSomething();
};

As opposed to something like:

2-1:

#define OK              (0)
#define ERR_NO_MEMORY   (1)
#define ERR_BAD_PARAM   (2)

Or:

2-2:

typedef enum _TResult
{
    EOk,
    EErrNoMemory,
    EErrBadParam,
    <...>
    EErrTimeOut,
    EErrFeedThePenguin
} TResult;

From your experience what would be the gotcha’s for any of the approaches?

  • 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-11T20:12:33+00:00Added an answer on May 11, 2026 at 8:12 pm

    The one thing that I’d comment about with per-class error codes is that you then aren’t able to write a single error logger (or at least not easily) due to the fact that the same code will mean different things depending on the class.

    That said, you can always use both. Have a global enum with common errors:

    enum GlobalErrors {
       EOk = 0,
       EErrOutOfMemory,
       // etc.
       EFreeErrorCodeBase
    };
    

    and then in classes you can have:

    class Something {
        enum ClassErrors {
           EErrCantInitialize = EFreeErrorCodeBase,
           EErrCorruptedData,
           // etc.
        };
    ...
    };
    

    Which gives you a place for global error codes and ensures your class error codes won’t overlap the globals (and this is maintained by the compiler).

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

Sidebar

Related Questions

I'm in the process of creating a class that stores metadata about a particular
Ok, I am in the process of creating a cms. There will be a
I'm currently creating an ecommerce site using Drupal and the Ubercart module, for each
Suppose that a process is creating a mutex in shared memory and locking it
I am in the process of creating an XML Schema and one of my
I'm in the process of creating a double-linked list, and have overloaded the operator=
I'm in the process of creating an app. I'd like to have a pared
I am in the process of creating an input form on a record specific
I'm in the process of creating a traditional desktop application, and I'd like to
I'm in the process of creating exercises in how to write a plug-in to

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.