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 } {
send [concat "(error " $err ")"] }
close $Source}
To test this I sent the invalid command 'what .b' rather than say
'button .b'.
I expected TCL/tk to send an error message using 'send' and continue
the loop. However what happens is that the loop exits with an error
message 'invalid command what' and on examination I found the message
has been sent using 'send'. So in some sense it was caught and yet
it was not caught because the loop exited. Puzzling.
On 1/27/24 10:08, Rich wrote:
Mark Tarver <dr.mtarver@gmail.com> wrote:Actually, you don't want [eval $Command] -- you just want $Command
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 } {
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 496 |
Nodes: | 16 (2 / 14) |
Uptime: | 55:30:14 |
Calls: | 9,759 |
Files: | 13,742 |
Messages: | 6,185,129 |