Please, consider the following code :
k = 0;
ret = Catch[
Check[
data = 1/k;
Print[Pi] ;
Throw[data, "RETURN"];
, Throw @ $Failed
];
, "RETURN"
]
In my mind, it should work this way:
if
k = 1(1)data = 1(2)Checkdoes nothing (because no message has been generated) (3)Catchcatchesdata(4)ret = 1if
k = 0(1)data = Complex Infinity(2)Checkwakes up because a message has been generated(Power::infy)and throws$Failed(3) but this throw has not the tag"RETURN", therefore it is not caught byCatchand a message(Throw::no catch)is generated.
On the opposite, what happens is:
if
k = 1... as expectedik
k = 0...ret = ComplexInfinity
To detect the point where I'am reasoning wrong, I added the Print command inside: Pi is printed even when k = 0 so I conjecture that Check evaluates its first argument, not returning the failexp until the whole computation has been completed. Two question:
is this behaviour related to the
HoldAllattribute ofCheck?how can I break at the generation of the first message ?
ret=Check[1/k,Throw@$Failed]? – unlikely Mar 17 '16 at 06:36