how to handle open() errors?

Discussion in 'C++' started by fabrizio, Nov 13, 2005.

  1. fabrizio

    fabrizio Guest

    Opening /dev/tap0, I have an error in fact open() returns -1.

    int fd = open("/dev/tap0",O_RDWR);
    if (fd == -1)
    {
    cerr<<"error opening interface"<<endl;
    }

    How can I handle the error? Essentially, how can I print the error to
    know the reason of it?

    Thanks.
    fabrizio, Nov 13, 2005
    #1
    1. Advertising

  2. fabrizio wrote:
    > Opening /dev/tap0, I have an error in fact open() returns -1.
    >
    > int fd = open("/dev/tap0",O_RDWR);
    > if (fd == -1)
    > {
    > cerr<<"error opening interface"<<endl;
    > }
    >
    > How can I handle the error? Essentially, how can I print the error to
    > know the reason of it?
    >
    > Thanks.
    >


    perror will print an error message to the standard error stream

    int fd = open("/dev/tap0",O_RDWR);
    if (fd == -1)
    {
    perror("error opening interface");
    }

    There are of coure no guarantees that the error message will be helpful.

    john
    John Harrison, Nov 13, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Dietrich
    Replies:
    1
    Views:
    625
    Joe Smith
    Jul 22, 2004
  2. Mark Goldin

    Errors, errors, errors

    Mark Goldin, Jan 17, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    920
    Mark Goldin
    Jan 17, 2004
  3. Jonas

    Handle errors in global.asax

    Jonas, Nov 16, 2005, in forum: ASP .Net
    Replies:
    7
    Views:
    7,135
    Patrice
    Nov 17, 2005
  4. Leon
    Replies:
    2
    Views:
    507
  5. =?ISO-8859-1?Q?KLEIN_St=E9phane?=
    Replies:
    3
    Views:
    439
    hanumizzle
    Oct 6, 2006
Loading...

Share This Page