473,395 Members | 1,452 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

how to handle open() errors?

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.

Nov 22 '05 #1
1 1179
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
Nov 22 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
by: Abhi | last post by:
FYI: This message is for the benefit of MS Access Community. I found that this prblem has been encounterd by many but there is hardly any place where a complete solution is posted. So I thought...
4
by: atv | last post by:
Whatis the proper way to handle errors from function calls? For example, i normally have a main function, with calls to mine or c functions. Should i check for errors in the functions called...
4
by: Claire | last post by:
I'm writing a realtime monitoring application acting as a Windows service. This service communicates to some instrumentation via a third party dll. TCP is the transport mechanism over the network....
0
by: Jonathan | last post by:
Hi. I'm using AxWebBrowser component to simulate a web browser in mi App. Everything works ok, but when open some page with script errors an error in my app is fired. Title: "Just-In-Time...
3
by: figelwump | last post by:
Hello, I'd like to be able to write an application that runs on a Windows XP machine and can capture and handle javascript errors from any web site that a user might encounter while using IE on...
3
by: clintonb | last post by:
Some programmers, and even Microsoft documents, say you should only throw exceptions for exceptional situations. So how are others handling all the other unexceptional errors? How are you...
2
by: Louis | last post by:
Hope somebody can tell me why this happens to filehandles... I am playing with perl packages, and I had all functions in one file. Now I want to split them into different files using package. ...
1
by: sranger | last post by:
When I try to use a System.IO.Ports.SerialPort object to read from a serial port, half of the time I have no problems. However, after I successfully read from the serial port, then close the...
5
by: Grant Edwards | last post by:
I'm trying to use the py-gnuplot module on windows, and have been unable to get it to work reliably under Win2K and WinXP. By default, it uses popen(gnuplotcmd,'w'), but in some situations that...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.