Skip to contentSkip to conversation

Compiling C++ modules

DISCUSSION Robert Hancock 1 participant 1 message Apr 28, 2006 4 messages not in the archive

lore
Share & tools
lore
#4 lore raw
In reply to a message not in the archive
Quoted 6 lines · Denis Vlasenko
Quoted 1 line

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.

Signature · 3 lines
Robert Hancock      Saskatoon, SK, Canada
To email, remove "nospam" from [email protected]
Home Page: http://www.roberthancock.com/