The -code option value has to be interpreted in conjunction with the
-level option which defaults to 1.
% puts [catch {return -code error -level 0}]
1
% puts [catch {return -code break -level 0}]
3
% puts [catch {return -code continue -level 0}]
4
Without the -level 0, the codes are seen one level up the stack
(defaulting to -level 1), not by the return invocation itself.
% proc xx {} {return -code break} ; # Defaults to -level 1
% catch {xx}
3
% proc yy {} {return -code break -level 2}
% proc zz {} {yy}
% catch yy
2
% catch zz
3
/Ashok
On 8/18/2022 2:58 AM, Alan Grunwald wrote:
Summary:
I've found the following:
% puts stdout [catch {incr i}]
0
% puts stdout [catch {error foo}]
1
% puts stdout [catch {return foo}]
2
% puts stdout [catch {break}]
3
% puts stdout [catch {continue}]
4
Which is all as expected and documented.
However
% puts stdout [catch {return -code ok}]
2
% puts stdout [catch {return -code error}]
2
% puts stdout [catch {return -code return}]
2
% puts stdout [catch {return -code break}]
2
% puts stdout [catch {return -code continue}]
2
I'd expect these to return 0, 1, 2, 3 and 4 as in the previous case.
What am I missing?
--- SoupGate-Win32 v1.05
* Origin: fsxNet Usenet Gateway (21:1/5)