One of the neat things the IMVU client has is balls-awesome crash handling. We do a number of things to ensure that, any time our client crashes for any reason, that we find out as much as we can about them. This serves a bunch of purposes: we use the raw number of crashes to determine whether or not we have broken something, and we use all the information we can get out of the crashes (stack traces, memory dumps, log files, and the like) to fix them.

One of the tricks to testing crash handling is that you can’t really do it without crashing. :) To that end, we have a large array of functions that exist only to crash our client. Moreover, we have parameterized them on the context in which we would like the crash to occur: with Python on the stack, without, from a WndProc, from within an exception handler, and so forth

This would be a terrible source of duplicated code, but for a satanic little trick that you can do with the C preprocessor. Since I’m such a nice guy, I’ll even tell you what it is right up front, so you can skip the rest of this post if you want:

Macros can be macro arguments.

Here’s how it works:

First, we’re going to define a list of crashes, using the C preprocessor:

Now, I’ll be the first one to wail in terror at how theoretically terrible the C preprocessor is, and what it does to
maintainability, but, in this case, at least, the payoff is undeniable: with very small effort, and without having to
build some kind of “CrashRegistry” framework, we can add additional crash cases to our client.