D: Fix out-of-source build for examples.
Add D to Travis CI.
D: Fix exception handling support.

The original code was ported from the C# module. It looks like it
tried to avoid reading TLS data by using a shared counter. However,
without also synchronizing on the counter check (or using atomics)
the code is racy (as far as I can see even in the original C#
implementation, although I'm not intimately familiar with its
concurrency model). At this point, it is cheaper to just do a TLS
load, as the code can be completely unsynchronized that way.