From: Csaba N. <csa...@t-...> - 2025-04-01 14:20:56
|
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://lists.sourceforge.net/lists/listinfo/tcl-core -- Csaba Nemethi https://www.nemethi.de mailto:csa...@t-... |