Throw an exception but "hide" the top frame?
aldanor via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Wed Dec 24 06:25:35 PST 2014
On Wednesday, 24 December 2014 at 14:11:37 UTC, Adam D. Ruppe
wrote:
> auto check(alias func)(int x, string file = __FILE__, size_t
> line = __LINE__) {
> /* snip */
> throw new Exception("%d < 0".format(result), file,
> line); // L10
Thanks! I guess that's what my confusion was partially about --
when exactly the __FILE__ and __LINE__ are substituted
(particularly in the case when you're dealing with templates).
It looks like this would even work with generic callables:
auto check(alias func)(ParameterTypeTuple!(func) args, string
__line__ = __LINE__, int __file__ == __FILE__) {
static if (is(ReturnType!(func) == void))
func(args);
else {
auto result = func(args);
if (result < 0)
throw new Exception("foo", __line__, __file__);
return result;
}
}
More information about the Digitalmars-d-learn
mailing list