I'm doing eval
on the content of file. The file is made out of labels which I parse. Each line has a label, and I have a proc
defined for each label, so that the eval
succeeds. However, sometimes users add new labels and then the eval
command fails, because of unknown command.
Is there a way to prevent Tcl from crashing when trying to eval
an unknown command?
Ideally, it should allow me to substitute with my own defined behaviour - such as priting an error and continuing with the eval
.
EDIT:
Unfortunately, I can only use Tcl 8.4.
I tried doing the following, as suggested here:
proc handle_unknown_label {cmd args} { ... }
and then:
rename unknown _old_system_unknown
rename handle_unknown_label unknown
catch {set ret [eval $x]} err
rename unknown handle_unknown_label
rename _old_system_unknown unknown
but I still get the same behavior for the eval
, and it prints the following errors:
procedure unknown is a protected proc and will not get renamed
procedure unknown is a protected proc and will not get overriden
procedure unknown is a protected proc and will not get renamed
procedure unknown is a protected proc and will not get overriden
unknown
proc. Your Tcl interpreter must be specially built to be extra-paranoid. – glenn jackman