C++ FAQ Lite

Friday 9 December 2005This is almost 19 years old. Be careful.

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.

» 5 reactions

Comments

[gravatar]
Oh yes, great resource, I've used it many times.
[gravatar]
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]
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]
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]
like your comment system btw ned, very nice!

Add a comment:

Ignore this:
Leave this empty:
Name is required. Either email or web are required. Email won't be displayed and I won't spam you. Your web site won't be indexed by search engines.
Don't put anything here:
Leave this empty:
Comment text is Markdown.