mirror of
https://github.com/dlang/phobos.git
synced 2025-04-28 22:21:09 +03:00
Fix for issue# 8398.
This commit is contained in:
parent
87a143e4a8
commit
ed22f41ec2
1 changed files with 15 additions and 2 deletions
|
@ -488,7 +488,9 @@ T errnoEnforce(T, string file = __FILE__, size_t line = __LINE__)
|
|||
|
||||
/++
|
||||
If $(D !!value) is $(D true), $(D value) is returned. Otherwise,
|
||||
$(D new E(msg, file, line)) is thrown.
|
||||
$(D new E(msg, file, line)) is thrown. Or if $(D E) doesn't take a message
|
||||
and can be constructed with $(D new E(file, line)), then
|
||||
$(D new E(file, line)) will be thrown.
|
||||
|
||||
Example:
|
||||
--------------------
|
||||
|
@ -507,6 +509,16 @@ template enforceEx(E)
|
|||
}
|
||||
}
|
||||
|
||||
template enforceEx(E)
|
||||
if (is(typeof(new E(__FILE__, __LINE__))) && !is(typeof(new E("", __FILE__, __LINE__))))
|
||||
{
|
||||
T enforceEx(T)(T value, string file = __FILE__, size_t line = __LINE__) @safe pure
|
||||
{
|
||||
if (!value) throw new E(file, line);
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
/++
|
||||
$(RED Deprecated. It will be removed in October 2012. Please use the version
|
||||
of $(D enforceEx) which takes an exception that constructs with
|
||||
|
@ -516,7 +528,7 @@ template enforceEx(E)
|
|||
$(D new E(msg)) is thrown.
|
||||
+/
|
||||
deprecated template enforceEx(E)
|
||||
if (is(typeof(new E(""))) && !is(typeof(new E("", __FILE__, __LINE__))))
|
||||
if (is(typeof(new E(""))) && !is(typeof(new E("", __FILE__, __LINE__))) && !is(typeof(new E(__FILE__, __LINE__))))
|
||||
{
|
||||
T enforceEx(T)(T value, lazy string msg = "") @safe pure
|
||||
{
|
||||
|
@ -529,6 +541,7 @@ unittest
|
|||
{
|
||||
assertNotThrown(enforceEx!Exception(true));
|
||||
assertNotThrown(enforceEx!Exception(true, "blah"));
|
||||
assertNotThrown(enforceEx!OutOfMemoryError(true));
|
||||
|
||||
{
|
||||
auto e = collectException(enforceEx!Exception(false));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue