mirror of
https://github.com/dlang/phobos.git
synced 2025-05-08 20:19:43 +03:00
Merge pull request #1062 from AndrejMitrovic/Fix8078
Issue 8078 - receiveOnly exceptions should be informative
This commit is contained in:
commit
f1ad5d359c
1 changed files with 31 additions and 4 deletions
|
@ -72,7 +72,7 @@ private
|
|||
import std.algorithm;
|
||||
import std.exception;
|
||||
import std.range;
|
||||
import std.range;
|
||||
import std.string;
|
||||
import std.traits;
|
||||
import std.typecons;
|
||||
import std.typetuple;
|
||||
|
@ -707,7 +707,14 @@ receiveOnlyRet!(T) receiveOnly(T...)()
|
|||
},
|
||||
( Variant val )
|
||||
{
|
||||
throw new MessageMismatch;
|
||||
static if (T.length > 1)
|
||||
string exp = T.stringof;
|
||||
else
|
||||
string exp = T[0].stringof;
|
||||
|
||||
throw new MessageMismatch(
|
||||
format("Unexpected message type: expected '%s', got '%s'",
|
||||
exp, val.type.toString()));
|
||||
} );
|
||||
static if( T.length == 1 )
|
||||
return ret[0];
|
||||
|
@ -715,6 +722,26 @@ receiveOnlyRet!(T) receiveOnly(T...)()
|
|||
return ret;
|
||||
}
|
||||
|
||||
unittest
|
||||
{
|
||||
static void t1(Tid mainTid)
|
||||
{
|
||||
try
|
||||
{
|
||||
receiveOnly!string();
|
||||
mainTid.send("");
|
||||
}
|
||||
catch (Throwable th)
|
||||
{
|
||||
mainTid.send(th.msg);
|
||||
}
|
||||
}
|
||||
|
||||
auto tid = spawn(&t1, thisTid);
|
||||
tid.send(1);
|
||||
string result = receiveOnly!string();
|
||||
assert(result == "Unexpected message type: expected 'string', got 'int'");
|
||||
}
|
||||
|
||||
//Explicitly undocumented. Do not use. To be removed in March 2013.
|
||||
deprecated bool receiveTimeout(T...)( long ms, T ops )
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue