473,386 Members | 1,621 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,386 software developers and data experts.

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 1504
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**********@Home.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
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...
0
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...
0
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...
1
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...
2
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++...
1
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...
3
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...
40
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:...
1
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...
40
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...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...
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...

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.