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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T17:45:52+00:00 2026-05-19T17:45:52+00:00

I was wondering what would be the best way to handle errors in an

  • 0

I was wondering what would be the best way to handle errors in an application in programming languages like C++, Java, C#.

I thought of creating a place where to store number related to error and warning messages .

For example :

10000 -> “Can’t read file”.
…
20000 -> “Buffer overflow”.
…
80000 -> “Critical stuff”.

I think it’s a good practice to map errors with numbers. It’s easier to find the error no matter which languages it’s displayed with. What do you guys think about that ? Is there a even better way to do that ?

Another point is, how to store them, how to create them ?

Is a big general enum a good solution ? Do we have to store them in a database ? In a file ?

It should be :

  • Easy to find an error in the code (ie. from the number).
  • Easy to add a new error (not using the same error number twice can be tricky if there are not at the same place).

What do you guys think about all that ?

Thanks in advance for your help and advices!

  • 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-19T17:45:53+00:00Added an answer on May 19, 2026 at 5:45 pm

    Using error codes to identify exceptions is not a bad practice.

    It can be very useful in a production environment to keep the log files shorter and also it can be used to internationalize error messages.

    On the other hand, when developing, it can be annoying to received an error code instead of a full blown error message with meaningful description. A developer has to go and check what the error code is about.

    In one of my projects (using Java) I have developed an hybrid approach. My root exception has a constructor that uses an Enum class. The Enum class contains a list of error codes + default error messages. Something like:

    public enum ErrorCodes {
    
        VALIDATION_ERROR(5001, "One of the objects cannot be validated"),
        RESOURCE_NOT_FOUND(4004, "The requested resource does not exist"),
    

    The root exception has also other constructors, so that a developer can override the default message:

    public CoreException(ErrorCodes _errorCode, final String message, final Throwable cause) {
       super(message, cause);
       errorCode = _errorCode.getCode();
    }
    
    
    public CoreException(ErrorCodes _errorCode, final String message) {
       super(message);
       errorCode = _errorCode.getCode();
    }
    

    When the exception is caught the Exception handler can decide (based on some configuration setting) to log the error and the message or the error only.
    A more sophisticated error handler could also look up a message in a specific language from a resource bundle based on the error code.

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

Sidebar

Related Questions

I was wondering what would be the best way to handle an application timeout,
i was wondering what would be the best way to code a browser plugin
I recently started learning backbone and was wondering what would be the best way
I was wondering, what would be the best way to validate an integer. I'd
I've been wondering what the best way to do this would be. I've got
Wondering what the best / good way of doing this would be in jQuery.
Hey im just wondering what would be the best collection to use when creating
I am wondering what would be the best approach to store, for let's say
I am wondering the best way to handle blocking computers after the users commit
C# 2008 SP1 I am wondering what is the best way to handle revision

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.