D-Programming-Language/phobos — pull request #1571 by quickfur (2013-09-12 21:36:34+00:00)
Title: Implement assumeWontThrow.

As discussed on the forum, one often needs to use `std.format.format` to format nice error messages inside an `assert`. However, since `format` cannot be made `nothrow`, this prevents the code from being made `nothrow`, even though under normal circumstances it indeed will never throw.

This pull implements an `assumeWontThrow` wrapper which wraps an expression inside a try block with a catch block that asserts false should the expression actually throw. This allows the wrapper to be made `nothrow`, and thus usable without undue encumbrence from `nothrow` functions. Thus, the original motivating case can now be implemented thus:
```
void func(int x) nothrow
{
assert(someCondition(x), assumeWontThrow(format("Error: x=%d fails to satisfy some condition", x)));
}
```