473,699 Members | 2,698 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

C library errors -> C++ exceptions

System: Pentium 4, Win32, gcc 3.3.3 cygwin

Does anyone know of a mechanism whereby C library functions can be made
to throw a (C++) exception in case a call fails? This would obviate
having to check the results of function calls individually at the point
of call.

I would also be nice to be able to specify that (some) floating point
IEEE 754 "exceptions " throw C++ exceptions (some of the time).

I note that the glibc documentation suggests that "traps" may be
enabled to cause fp "exceptions " to generate a SIGFPE signal. This
suggests a possible workaround whereby a signal handler could catch the
SIGFPE signal and throw an exception (OTOH I have heard that signals
and C++ exceptions do not necessarilly mix well). This is academic, as
I have not found a way - perhaps it is not possible - to enable fp
traps for my system.

Any help/ideas appreciated,

--
Lionel B

Jul 22 '05 #1
2 1510
On 7 Oct 2004 03:13:43 -0700, "Lionel B" <go****@lionelb .com> wrote:
System: Pentium 4, Win32, gcc 3.3.3 cygwin

Does anyone know of a mechanism whereby C library functions can be made
to throw a (C++) exception in case a call fails? This would obviate
having to check the results of function calls individually at the point
of call.

I would also be nice to be able to specify that (some) floating point
IEEE 754 "exceptions " throw C++ exceptions (some of the time).

I note that the glibc documentation suggests that "traps" may be
enabled to cause fp "exceptions " to generate a SIGFPE signal. This
suggests a possible workaround whereby a signal handler could catch the
SIGFPE signal and throw an exception (OTOH I have heard that signals
and C++ exceptions do not necessarilly mix well). This is academic, as
I have not found a way - perhaps it is not possible - to enable fp
traps for my system.

Any help/ideas appreciated,


To catch system-generated exceptions in your code, you need to use
C-style SEH (structured exception handling). Then, you need to wrap
the C functions in C++ functions which check the return value, then
throw something appropriate as a C++ exception.

It is possible that cygwin already does something under the covers
with SEH; check your documentation for details.

--
Bob Hairgrove
No**********@Ho me.com
Jul 22 '05 #2
Bob Hairgrove wrote:
On 7 Oct 2004 03:13:43 -0700, "Lionel B" <go****@lionelb .com> wrote:
System: Pentium 4, Win32, gcc 3.3.3 cygwin

Does anyone know of a mechanism whereby C library functions can be madeto throw a (C++) exception in case a call fails? This would obviate
having to check the results of function calls individually at the pointof call.

I would also be nice to be able to specify that (some) floating pointIEEE 754 "exceptions " throw C++ exceptions (some of the time).

/snip/
To catch system-generated exceptions in your code, you need to use
C-style SEH (structured exception handling). Then, you need to wrap
the C functions in C++ functions which check the return value, then
throw something appropriate as a C++ exception.
For the non-floating point errors, if I'm going to write C++ wrappers
which check return values for the functions I am interested in - a
reasonable (if tedious) solution, I guess - it seems to me I shouldn't
have to get into SEH issues (a Good Thing, as far as I'm concerned - a
brief look has convinced me that trying to combine SEH with C++
exception handling would be nightmarish).
It is possible that cygwin already does something under the covers
with SEH; check your documentation for details.


Couldn't find anything relevant to my query in docs or mailing list
archives. Perhaps a re-post to the Cygwin mailing list might be in
order.

Thanks,

--
Lionel B

Jul 22 '05 #3

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

Similar topics

0
1811
by: TGF | last post by:
Hello, I am creating a console app. I try to link a static library by including it in the Linker-Input-Additional Dependencies field under the Project properties. Then I specify the path to the library in Linker-General-Addition Library Directories field under the Project options. The first question I have is....is this the correct way to include a static library. If not, then what is the correct way to do it (I need to make .NET...
0
1210
by: TGF | last post by:
Hello, I am creating a console app. I try to link a static library by including it in the Linker-Input-Additional Dependencies field under the Project properties. Then I specify the path to the library in Linker-General-Addition Library Directories field under the Project options. The first question I have is....is this the correct way to include a static library. If not, then what is the correct way to do it (I need to make .NET...
0
1628
by: TGF | last post by:
Hello, I am creating a console app. I try to link a static library by including it in the Linker-Input-Additional Dependencies field under the Project properties. Then I specify the path to the library in Linker-General-Addition Library Directories field under the Project options. The first question I have is....is this the correct way to include a static library. If not, then what is the correct way to do it (I need to make .NET...
1
4325
by: mccoyn | last post by:
I'm porting an old project to use .NET. When I try to link in a static library (.lib) that has a single managed class in it. I get the following errors: LINK : error LNK2020: unresolved token (0600000E) PatInfo::.ctor LINK : error LNK2020: unresolved token (0600000F) PatInfo::Finalize LINK : fatal error LNK1120: 2 unresolved externals I've striped everything out of this library except for the single class which has an empty constructor...
2
1966
by: Michael Braitmaier | last post by:
I have a quite severe problem. I am trying to compile a C++ library initially written for VC++ 6. To make the library available for .NET languages I want to compile the library as managed C++ library. As the library is utilizing DirectX 9 it bases on COM. This causes me quite some troubles as I get compile errors caused by the include files included through the DirectX 9 header file. The errors occur in unknwn.h, objbase.h and ObjIdl.h. ...
1
7098
by: Jim | last post by:
Have fully operational software package developed on VB.NET that worked until Jan 1 2003, with early stage deployments on Oct 10, Oct 23, Nov 11, Dec 12 and Dec 30. When attempted final deployment on Jan 2, 2004 got following messages and errors... I reset everything and tried several times agian. Then erased the setup project and tried to rebuild a new one with the same errors. PLease note... ALL this this code ran perfectly five minutes...
3
5112
by: Charles Nicholson | last post by:
Hello all- I have some static C++ libraries that I wrote in VS2003 but which upgraded fine when i went to VS2005 Pro. In them i overload the global versions of operators new, new, delete, and delete. I also use the STL and parts of boost (shared_ptr<> and weak_ptr<>) pretty heavily. They have dependencies on various windows libs (dbghelp, winsock, etc...). These static libraries have no common runtime support at all and use the...
40
2793
by: Robert Seacord | last post by:
The CERT/CC has released a beta version of a secure integer library for the C Programming Language. The library is available for download from the CERT/CC Secure Coding Initiative web page at: http://www.cert.org/secure-coding/ The purpose of this library is to provide a collection of utility functions that can assist software developers in writing C programs that are free from common integer problems such as integer overflow, integer...
1
1324
by: Mihai Velicu | last post by:
I created a control library and i created a control.I can test it is ok.I added this control to a form .Run the form is ok also.After i modified the control to add some new features and i had some errors i don't have access to the form .I rebuild the solution, i rebuild the control library, is for nothing.Even I undo the changes, i recompiled the control library , so now is like at the beggining , i still don't have access to the form, only...
40
2349
by: Angus | last post by:
Hello I am writing a library which will write data to a user defined callback function. The function the user of my library will supply is: int (*callbackfunction)(const char*); In my libary do I create a function where user passes this callback function? How would I define the function?
0
8704
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9192
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8939
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8895
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6545
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5879
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4637
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3071
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2015
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.