Can you convert a signal to an exception?

Can you convert a signal to an exception?

Post by Fergus Henders » Tue, 18 Feb 1997 04:00:00



[Crossposted and followups redirected to comp.unix.programmer,
since this has drifted off-topic for comp.std.c++.]



>: I would like to have a handler for a program-generated signal
>: (like SEGV) throw an exception, so I can get the benefits of
>: stack unwinding.

>First of all, you can't catch SEGV. You program will be killed
>by the kernel, and rigtfully so.

No, that's not correct.  All the Unix systems I've tried it on --
Linux, Solaris, Alpha/OSF, and IRIX -- allow you to catch SIGSEGV.
You can even use mprotect() to turn off write protection and then
continue.

Here's what Mike Stump from Cygnus had to say when this question
came up last time (look for the thread "turning unix signals
into G++ exceptions" with dejanews):

 | Throwing an exception from within a signal handler is not valid ANSI
 | C++, if you do so, you do so at your own risk.  I have tried to make
 | the compiler (g++) so that exceptions can be asynchronous (thrown from
 | inside signal handlers and everything just work), but some items
 | remain it you want it to work flawlessly all the time.  It should work
 | ok some/most of the time now.
 |
 | If you run the instruction stream up to the next call instruction
 | before throwing the exception you should be really safe.

--

WWW: <http://www.cs.mu.oz.au/~fjh>   |  of excellence is a lethal habit"

---
[ comp.std.c++ is moderated.  To submit articles: try just posting with      ]

[ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
[ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]