Am 27.01.24 um 17:45 schrieb Gerald Lester:
On 1/27/24 10:08, Rich wrote:
Mark Tarver <[email protected]> wrote:
I'm trying to trap errors inside an event loop. Here is the relevant
code
proc enact {File} {
set Source [open $File r]
set Data [read $Source]
set Command [trim $Data]
overwrite $File
catch [eval $Command] err
if { $err != 0 } {
...
Actually, you don't want [eval $Command] -- you just want $Command
To put it together: The correct invocation would be:
if {[catch $Command result]} {
# an error has happened
# the error message is in $result
} else {
# it went smoothly
# the reult of $Command is in $result
}
Catch executes the 1st arg, i.e.
catch $Command result
is the same as
set result [eval $Command]
- with the difference that it catches the errors.
Also note that the command is executed in the current scope. I.e. if
Command is "set a 3", then the variable a inside the proc enact will be
set. Most systems that execute such commands, e.g. Tk button commands
etc., rather use the global level via
catch {uplevel #0 $Command}
Christian
--- SoupGate-Win32 v1.05
* Origin: fsxNet Usenet Gateway (21:1/5)