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)Check
does nothing (because no message has been generated) (3)Catch
catchesdata
(4)ret = 1
if
k = 0
(1)data = Complex Infinity
(2)Check
wakes 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 byCatch
and 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
HoldAll
attribute ofCheck
?how can I break at the generation of the first message ?
ret=Check[1/k,Throw@$Failed]
? $\endgroup$