Posted to tcl by kbk at Sat Mar 15 17:01:00 GMT 2025view raw
- proc doit {script} {
- set code [catch {uplevel 1 $script} result opts]
- dict incr opts -level; # repeat any exception in the caller
- return -options $opts $result
- }
- puts "Normal operation"
- for {set i 0} {$i < 3} {incr i} {
- doit {puts $i}
- }
- puts "Break"
- for {set i 0} {$i < 5} {incr i} {
- doit {if {$i > 3} break; puts $i}
- }
- puts "Continue"
- for {set i 0} {$i < 5} {incr i} {
- doit {if {$i < 3} continue; puts $i}
- }
- puts "Return"
- proc tryit {} {
- doit {return {it worked}}
- }
- puts [tryit]
- puts "Stack trace of errors:"
- proc fail {} {
- doit {error {Test an error} {Test an error} {MYERROR}}
- }
- set status [catch [fail] result]
- puts "status = $status"
- puts "result = $result"
- puts "stacktrace = $::errorInfo"