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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T17:51:27+00:00 2026-05-23T17:51:27+00:00

I would like to have error codes in my Java project, but they should

  • 0

I would like to have error codes in my Java project, but they should have variable String descriptions. For example, I might have two BadCharacterCount errors, but I’d like to represent them as two different strings, e.g. “Bad character count: expected 50, got 60” and “Bad character count: expected 40, got 70.” I’d like to be able to recognize both of these cases as BadCharacterCount errors, and ideally have these in an enum of some sort.

There’s a nice discussion of a similar problem here:
Best way to define error codes/strings in Java?

However, they don’t deal with the case of variable error Strings… Any ideas?

  • 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-23T17:51:28+00:00Added an answer on May 23, 2026 at 5:51 pm

    I think your two error descriptions:

    Bad character count: expected 50, got 60

    And:

    Bad character count: expected 40, got 70.

    Are already the same. The string is:

    Bad character count: expected %s, got %s.

    Then when you need to construct the error message, just make sure to pass it through String.format:

    String.Format(Error.BadCharacterCount, 50, 60)
    

    And

    String.Format(Error.BadCharacterCount, 40, 70)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to evaluate JPA on an existing project. The database model and
I am considering starting a project which is used to generate code in Java
When I run javadoc on my java source code, I get this error for
I have an existing project that uses @Override on methods that override interface methods,
I have recently inherited some Java code and need to integrate it into a
I would like to learn how to escape dot in GString so groovy (1.8)
I have a question in Java how can I check if an image http
I'm currently working on a plug-in for Eclipse that translates some custom Java code
Our project in eclipse approximately shows the following folders: application - src - JRE
We've got a product that's made up of C++ and Java parts. The C++

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.