From: Neil M. <ne...@cs...> - 2004-07-24 16:22:46
|
[break] and [return -code] are two different things. Example: catch {break} ;# -> 3 (break) catch {return -code break} ;# -> 2 (return) proc foo {} { break } catch {foo} ;# -> 1 (error - invoked break outside loop) proc bar {} { return -code break } catch {bar} ;# -> 3 (break) The return -code stuff causes a TCL_RETURN return code, which is then=20 converted to a TCL_BREAK return code after one stack level has unwound.=20= To get them to be equivalent, you can use (in 8.5) [return -code break=20= -level 0]. The reason for the difference (without the -level stuff) is=20= so that stuff like this works: proc MyBreak {} { return -code break } This will work just like the built-in [break] command. On 24 Jul 2004, at 17:00, Martin Lemburg wrote: > Hello Lars, > > you are right, the TIP 90 is what I ment, but it is very difficult to=20= > understand this document.. > > In my eyes, it is not a lack of functionality, but more or less a=20 > bug, that catching e.g. "break" returns the right value, but catching=20= > "return -code break" always returns not the matching value. > > Why a TIP and not a simple bugfix to let the catch command return the=20= > right value? > > The TIP 90 is about extending the "return" and "catch" functionality,=20= > right? > My question is about the normal, regular and expected behaviour of=20 > the combination of "catch" and "return -code ...". > > Ok - in v8.5 the wanted functionality exists, so I have only to wait=20= > and then to switch to the this version. > > No problem for my private projects, a big problem for the company=20 > projects! > > Thanks and best regards, > > Martin Lemburg > > > > Lars Hellstr=F6m wrote: > At 01.29 +0200 04-07-24, Martin Lemburg wrote: > [stuff deleted] > > ... is not conform to the man pages of the return and the catch=20 > command, > because the catch command should return the values of the exceptional > return codes. And in the return man page is to be read, that the -code > option allows to create exceptional return codes. > > So - what is going wrong? Should I file this as a bug on=20 > sourceforge.net, > or is this already known and documented in the bug database, or=20 > corrected > in v8.4.6+? > > And - I see the differences from "return" and "return -code return",=20= > but > how should I differentiate via "catch" these two cases? > > Take a look at > TIP #90: Enable [return -code] in Control Structure Procs > http://purl.org/tcl/tip/90 > The descriptions there should answer your questions. > > Lars Hellstr=F6m > > > > > > =20= |