[lug] g++ signals and exceptions question

Jonathan Briggs zlynx at acm.org
Wed May 15 12:55:38 MDT 2002


I was thinking of using it in a situation where my program is doing some
processing, and it gets hit with a signal (SIGHUP for example) telling
it to rotate its log files.

The program is busy, it has lots of objects allocated on the stack,
etc...

If I just siglongjmp out of my signal handler, all those stack objects
will be lost and never destroyed properly.  My other choice is to check
for a signal in my program loop.  I have to either clutter up the code
by doing this often or accept that my program will ignore the signal
until it feels like getting back to the signal check.

Here's an example of how I'd use it:

while(running) {
	try {
		do_stuff();
	} catch( const SIGHUP_exception& e ) {
		rotate_logs();
	} catch( const signal_exception& e ) {
		running = false;
	}
}

The link that Ralf Mattes provided
(http://www.cs.wustl.edu/~schmidt/signal-patterns.html) led me to think
about some other methods, but so far I haven't found a method that
doesn't require checking a flag.

The entire situation in C with error return codes and needing to check
them is the reason C++ has exceptions.  This situation with needing to
check signal flags seems similar to me.

On Wed, 2002-05-15 at 12:31, Tkil wrote:
> Looking at it another way, where would you catch the exception
> "caused" by a signal?
> 
> Maybe if you can give an example of how you'd like to use such a
> construct?
-- 
Jonathan Briggs
jbriggs at esoft.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 232 bytes
Desc: This is a digitally signed message part
URL: <http://lists.lug.boulder.co.us/pipermail/lug/attachments/20020515/6be5e504/attachment.pgp>


More information about the LUG mailing list