Skip to content

Instantly share code, notes, and snippets.

@Yoplitein
Last active August 29, 2015 14:06
Show Gist options
  • Save Yoplitein/3b07090caadff0d20f36 to your computer and use it in GitHub Desktop.
Save Yoplitein/3b07090caadff0d20f36 to your computer and use it in GitHub Desktop.
D unittesting helper to ensure certain exceptions are thrown
void ensure_throws(ExceptionType = Exception)(void delegate() callable, string message = "")
{
import core.exception: AssertError;
try
{
callable();
assert(false, message);
}
catch(ExceptionType err) {}
catch(AssertError err)
throw err;
catch(Throwable err)
assert(false, "callable threw an unexpected exception");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment