assert(expression, error)
Andrej Mitrovic
andrej.mitrovich at gmail.com
Sat Feb 12 06:25:32 PST 2011
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.
More information about the Digitalmars-d-learn
mailing list