C library errors -> C++ exceptions

From: Lionel B (google_at_lionelb.com)
Date: 10/07/04


Date: 7 Oct 2004 03:13:43 -0700

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


Relevant Pages

  • Re: unexpected exception handler
    ... Yes and no. Generic library functions can't really ... but they should a) carefully document exceptions they may ... strategy is part of the API and should be documented. ...
    (microsoft.public.vc.language)
  • Re: C vs C++ in Embedded Systems?
    ... > Exceptions don't make any difference here. ... exceptional condition in a fully general function into the *spec* of the ... versions of library functions that may throw exceptions are always used, ... where the exception is caught at the lowest level (the wrapper), ...
    (comp.arch.embedded)
  • Re: [OT] Re: C Object System
    ... Laurent Deniau wrote: ... Are traps exceptions? ... What COS provides is a service which converts automatically registered signals into exceptions. ... I have developed an extension for lcc-win32 to implement DBC, ...
    (comp.lang.c)
  • Re: division by zero mystery
    ... Trapping is possible for floating point exceptions according to the C ... LIA-1 does not require that traps be precise. ... When arithmetic exceptions do trap, ... signal-handler mechanism allows trap-andterminate (either default ...
    (comp.programming)
  • Re: IO locked error
    ... That traps all IO errors though... ... you dont seem to have them anymore that I know of ... I still want IO errors like file not found and stuff to throw exceptions ... Prev by Date: ...
    (microsoft.public.dotnet.languages.vb)