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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T20:00:36+00:00 2026-05-20T20:00:36+00:00

When something goes wrong in a classic linux c/c++ software we have the magic

  • 0

When something goes wrong in a classic linux c/c++ software we have the magic variable errno that gives us a clue on what just went wrong.

But where is those errors defined?

Let’s take a example (it’s actually a piece from a Qt app, therefore the qDebug()).

if (ioctl(file, I2C_SLAVE, address) < 0) {
    int err = errno;
    qDebug() << __FILE__ << __FUNCTION__ << __LINE__ 
        << "Can't set address:" << address
        << "Errno:" << err << strerror(err);
     ....

The next step is to look at what that errno was so we can decide if we just quit or try to do something about the problem.

So we maybe add a if or switch at this point.

if (err == 9)
{
    // do something...
}
else 
{
    //do someting else
}

And my question is where to find the errors that “9” represents?
I don’t like that kind of magic numbers in my code.

/Thanks

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

    They are generally defined in /usr/include/errno.h* and are accessible by including errno.h:

    #include <errno.h>
    

    I write out both the errno value and its textual meaning when reporting an error, getting the textual meaning via strerror():

    if (something_went_wrong)
    {
        log("Something went wrong: %s (%d)", strerror(errno), errno);
        return false;
    }
    

    From a Linux shell, however, you can use the perror utility to find out what different errno values mean:

    $ perror 9
    OS error code   9:  Bad file descriptor
    

    EDIT:
    Your code should be changed to use the symbolic value:

    if (err == EBADF)
    {
        // do something...
    }
    else 
    {
        //do someting else
    }
    

    EDIT 2: * Under Linux, at least, the actual values are defined in /usr/include/asm-generic/{errno,errno-base}.h and other places, making it a bit of a pain to find them if you want to look at them.

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

Sidebar

Related Questions

I have an array but something goes wrong with it, here is my code
I have a code that goes something like: $cipher_alg = MCRYPT_RIJNDAEL_128; $decrypted_string = mcrypt_decrypt($cipher_alg,
I have a CSV file that goes something like this: ['Name1', '', '', '',
I have a problem with Python + SQLAlchemy. When something goes wrong (in my
I have a console application in C#. If something goes wrong, I call Environment.Exit()
I'm using Django with MySQL and South, and everything's just dandy...until something goes wrong
I have implement dining philosophers problem in java but something goes wrong and it
I have a Javascript functions which throw exceptions if something goes wrong. I have
Usually, Firebug gives a half decent error message when something goes wrong or doesn't
if something goes wrong when mapreduce is outputing on temp collection, what's happen? Is

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.