Exception Specifications

P

Pete Becker

Stuart said:
Thinking about it, though, presumably if there are two or more
such situations, you'd need to keep changing the unexpected handler?

The usual idiom (if there is one) is to use a class whose constructor
installs the handler you want and whose destructor restores the previous
handler.

You can also do it with one handler, but it's more complicated. You have
to detect the type that was thrown (by rethrowing the original exception
and catching it by type), then throw the appropriate replacement.

--

-- Pete

Author of "The Standard C++ Library Extensions: a Tutorial and
Reference." For more information about this book, see
www.petebecker.com/tr1book.
 
P

Pete Becker

Jens said:
I appreciate that this doesn't have to be the case. I'm just wondering
what value exception specifications can add to simple catch blocks.

The difference is in who manages the problem. try/catch blocks are a
local solution; an unexpected handler is global.

--

-- Pete

Author of "The Standard C++ Library Extensions: a Tutorial and
Reference." For more information about this book, see
www.petebecker.com/tr1book.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,526
Members
44,997
Latest member
mileyka

Latest Threads

Top