For the second time in two weeks, I happened upon Marshall Cline's C++ FAQ Lite. I'm not sure why it's called "Lite", because it is a huge list of hard questions, expertly answered. I thought I had shone a flashlight into every dark corner C++ had to offer, but I learned a few things poking around.

For example, in the answer to What does throw; mean? Where would I use it?, I learned that you can use throw even when not lexically nested in a catch:

void handleException()
{
  try {
    throw;
  }
  catch (MyException& e) {
    // ...code to handle MyException...
  }
  catch (YourException& e) {
    // ...code to handle YourException...
  }
}

void f()
{
  try {
    // ...something that might throw...
  }
  catch (...) {
    handleException();
  }
}

(We can argue over whether this is a good idea: my point is I didn't even know it was possible in the language.) And in What should be done with macros that contain if? (and the three questions that follow it), Cline explores all of the fiddly details that you need to consider when writing macros of any interesting complexity.

The whole FAQ is amazing like this: chock-full of top-notch technical detail.

tagged: » 5 reactions

Comments

[gravatar]
Damien Katz 2:06 PM on 9 Dec 2005

Oh yes, great resource, I've used it many times.

[gravatar]
Anonymous 5:24 PM on 9 Dec 2005

Thanks for reminding me that I really want to spend some time looking through this FAQ! BTW, I believe the reason for it being called Lite is answered by questions 3.1 and 3.2 of the FAQ:
"At last count, the C++ FAQ Book is 500% larger than the C++ FAQ Lite."

[gravatar]
Damien Katz 12:10 AM on 10 Dec 2005

After ruminating a while, I've determined the implications the exception thing are profound. For instance, you can have hot pluggable/swappable exception handlers. Yowza!

I'm sure there's a design somewhere I can complicate^H^H^H^H^H^H^H improve armed with this knowledge..

[gravatar]
ben 4:17 AM on 14 Dec 2005

i've not bothered with dynamically swappable exception handlers, but compile time configurable ones are pretty easy to implement, and quite useful in (possibly limited) situations. such as a unit test runner that can catch the kinds of exceptions that may be thrown by the tests it runs, even if those are different from the exceptions it caught by a different set ot tests.

[gravatar]
ben 4:18 AM on 14 Dec 2005

like your comment system btw ned, very nice!

Add a comment:

name
email
Ignore this:
not displayed and no spam.
Leave this empty:
www
not searched.
 
Name and either email or www are required.
Don't put anything here:
Leave this empty:
URLs auto-link and some tags are allowed: <a><b><i><p><br><pre>.