Re: Compiling C++ modules

Robert Hancock
2006-04-28T00:04:20Z

Denis Vlasenko wrote:
>> Additionally, C++ guarantees that if an exception is thrown after
>> spin_lock() is called, then the spin_unlock() will also be called.
>> That's an interesting mechanism by itself.
>
> Life gets even more interesting when you hit another exception
> inside destructor(s) being executed due to first one.
> Say, spin_unlock() discovers that lock is already unlocked
> and does "throw BUG_double_unlock".

You're not allowed to throw exceptions from inside the stack unwinding
caused by another exception, terminate() gets called in this case. In
most cases this isn't too hard to avoid, you just have to ensure that
exceptions don't get thrown out of destructors. Your example isn't very
good, why would you throw an exception in that case? The caller isn't
going to be able to do anything useful with it since it's because of a
coding bug, some kind of assert or BUG() would be more logical.

--
Robert Hancock Saskatoon, SK, Canada
To email, remove "nospam" from hancockr@nospamshaw.ca
Home Page: http://www.roberthancock.com/