From: Donal F. <don...@ma...> - 2025-04-01 15:24:33
|
The original code doesn't work because [while] converts TCL_BREAK into TCL_OK (or is bytecode-compiled to something equivalent). By the time it gets to the [try], it's already gone. Differentiating these is a sufficiently unusual requirement that we have no explicit support for it. Donal. -------- Original message -------- From: Csaba Nemethi <csa...@t-...> Date: 01/04/2025 15:21 (GMT+00:00) To: tcl...@li... Subject: Re: [TCLCORE] handling loops interruption within a 'try' The following *restructured* code works for me as expected: proc p {} while {[some_expensive_query]} { # .... if {[some_intervening_condition]} { return -code break ;# -level 1 } # .... } } try { p } on break {} { puts " ---- break ----" puts "Loop interrupted by break" } on ok {} { puts "Loop completed normally" } finally { puts "done" } Am 01.04.25 um 07:27 schrieb Massimo Manghi: > I apologize for (ab)using this mailing list to ask a question that maybe > has a trivial answer. > > I just can't have the 'on break' clause be triggered in a loop > controlled by a 'try' construct > > try { > while {[some_expensive_query]} { > > # .... > > if {[some_intervening_condition]} { > return -code break -level 0 > } > > # .... > } > } on break {} { > puts " ---- break ----" > puts "Loop interrupted by break" > } on ok {} { > puts "Loop completed normally" > } finally { > puts "done" > } > > and you have a normal termination even though the loop was interrupted > prematurely by [some_intervening_condition] > > I can get what I want by raising an exception with 'throw' and then > using the trap clause which allows extra control over the cause of the > exception (-errorcode receives no special treatment unless the option - > code error is passed) but what is the purpose of the 'on break' clause > if it's not handling a break? > > -- Massimo > > > _______________________________________________ > Tcl-Core mailing list > Tcl...@li... > https://urldefense.com/v3/__https://lists.sourceforge.net/lists/listinfo/tcl-core__;!!PDiH4ENfjr2_Jw!HEnJRLIzKYhQhoP6uLmD3-X_vyVjELprni_4haY-9QlMVUvAsyae59IdzAhgOQCvj9KRwmBTjlRcm33Vj8Nf9D110XEqyXSCArc5BMUn$[lists[.]sourceforge[.]net] -- Csaba Nemethi https://urldefense.com/v3/__https://www.nemethi.de__;!!PDiH4ENfjr2_Jw!HEnJRLIzKYhQhoP6uLmD3-X_vyVjELprni_4haY-9QlMVUvAsyae59IdzAhgOQCvj9KRwmBTjlRcm33Vj8Nf9D110XEqyXSCAsaHg4WY$[nemethi[.]de] mailto:csa...@t-... _______________________________________________ Tcl-Core mailing list Tcl...@li... https://urldefense.com/v3/__https://lists.sourceforge.net/lists/listinfo/tcl-core__;!!PDiH4ENfjr2_Jw!HEnJRLIzKYhQhoP6uLmD3-X_vyVjELprni_4haY-9QlMVUvAsyae59IdzAhgOQCvj9KRwmBTjlRcm33Vj8Nf9D110XEqyXSCArc5BMUn$[lists[.]sourceforge[.]net] |