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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T00:58:59+00:00 2026-05-22T00:58:59+00:00

I try to figure out how the new system_error together with error_code , error_category

  • 0

I try to figure out how the new system_error together with error_code, error_category and not the least the (meant to implement portable error reporting) error_condition should be used.

I think by reading boost.system I understand how I should use error_codes and error_category. The description leaves out how this is used in conjunction when throwing an exception with ´system_error`, but from the interface from that class I can guess.

class system_error : public runtime_error {
public:
  // [...]
  system_error(error_code ec, const string& what_arg);
  system_error(int ev, const error_category& ecat, const string& what_arg);
  system_error(int ev, const error_category& ecat);
  // [...]

So, I throw a system_error-exception with the right int+error_category or error_code with its error_category()-method.

But whats the way to provide the portable interface with error_condition?

Both error_code and error_category both have method default_error_condition:

class error_category {
public:
  // [...]
  virtual error_condition default_error_condition(int ev) const noexcept;
  // [...]

class error_code {
public:
  // [...]
  error_condition default_error_condition(int ev) const noexcept;
  // [...]

The error_category-Instances should be pre-created, for example (user-code):

struct AppCategory : public error_category { 
  const char *name() const noexcept override {
    return "application"; } 
  string message(int ev) const override {
    switch(ev) {
      case 14: return "error message";
      default: return "???";
    }
  } 
  error_condition default_error_condition(int ev) const noexcept override {
     ... ??? ...
  }
};

My questions implementing this:

  • Should I implement default_error_condition in error_category, and how?
  • Or how do I connect error_codes to the proper error_conditions,
  • and should I pre-construct error_condition instances?
  • A class error_code is not supposed to be provided by the user (me), right?

Is there a good example where I can take a look at code how error_condition is supposed to be extended by the user, in conjunction with system_error-exceptions?

  • 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-22T00:59:00+00:00Added an answer on May 22, 2026 at 12:59 am

    If the error codes for your error category can be mapped to one of the std::errc error codes then default_error_condition should do that mapping, and return a std::error_condition with a category of std::generic_category() and a value of the corresponding std::errc enum value. Otherwise it should return an error_condition referring to that category.

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

Sidebar

Related Questions

I couldn't figure out the reason why i get this error while i try
I try to figure out what -beginUpdates and -endUpdates is actually good for. Adding
I'm try to figure out how to handle the following scenario. In general, i
Try to see which cast is faster (not necessary better): new c++ case or
I am having the error message:I can`t figure out what is wrong. Can someone
Try loading this normal .jpg file in Internet Explorer 6.0. I get an error
I am very new to RegEx -- so can someone please help me figure
I can't figure it out for the life of me.. I'm using SQL DataSet
I have the code below which I now need to figure out how to
I get the error below when I try to run the application I am

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.