Re: signal handling and (structured) exception handling
On Oct 14, 4:54 am, Ian Collins <ian-n...@hotmail.com> wrote:
Peter wrote:
On Oct 12, 12:28 pm, James Kanze <james.ka...@gmail.com> wrote:
The standard could simply claim, that on machines which
support memory protection, a C++exceptionshould be thrown
instead of a signal. This would cover all of the platforms
I have to deal with (various UNIXs and Windows).
Except that this can't be made to work under Solaris, on a
Sparc.
SOLARIS also has signals for SIGSEGV and floating point
exceptions.
I used to convert structured exceptions on Windows into C++
exceptions by setting the matching handler and throw from
this handler a C++ exception matching the structured
exception code -- to be able to catch different types of
exceptions depending on what had happend.
Both, the signal handlers and structured exception handling
are asynchron.
I think it is just a matter of the compiler -- to create
code, which is able to deal with exceptions thrown from a
signal handler -- compiler switch /EHa with Microsofts
Visual C++.
I don't think you'll find any *nix compiler/runtime that
supports throwing exceptions from a signal handler.
Officially, or practically:-)? I think most compilers fail to
document this. (I know of the problems under Solaris on a Sparc
from personal conversations with the authors of Sun CC. Not
from documentation.)
Of course, the Posix standard says that there are only a limited
number of things you can do in a signal handler, and raising an
exception obviously isn't one of them. But the Posix standard
is only concerned with C; it doesn't say you can call a virtual
function, either, but that's not a problem.
More generally: how does Microsoft handle structured exceptions
if the fault occurs when malloc is in the middle of updating its
data structures? Of course, this can only happen if you've
corrupted the free space arena somehow (or there is a bug in
malloc), but isn't that one of the most common causes of a
segment violation?
More generally, implementable or not, structured exceptions
aren't reliable. There are special cases (e.g. plug-ins for
non-critical applications) where they represent an acceptable
risk, especially since with the Microsoft compiler, each plug-in
(DLL) has its own heap, but I certainly wouldn't use them in
anything critical.
--
James Kanze