Yeah, enforce is great. Here's one way I use it for external libraries in one of my projects:
class sndfileException : Exception { this(SNDFILE *sndfile) { super(to!string(sf_strerror(sndfile))); } } auto handle = sf_open(args); // on failure returns null enforce(handle !is null, new libsndException()); The sf_strerror function is from a library function that returns a C string with the last error that occurred for a specific handle (SNDFILE*). So I just made a simple exception wrapper for it in the libsndException class.