Prevent Tcl from crashing on unknown command -
i'm doing eval on content of file. file made out of labels parse. each line has label, , have proc defined each label, eval succeeds. however, users add new labels , eval command fails, because of unknown command.
is there way prevent tcl crashing when trying eval unknown command?
ideally, should allow me substitute own defined behaviour - such priting error , continuing eval.
edit:
unfortunately, can use tcl 8.4.
tried doing 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 still same behavior eval, , prints following errors:
procedure unknown protected proc , not renamed
procedure unknown protected proc , not overriden
procedure unknown protected proc , not renamed
procedure unknown protected proc , not overriden
i think i'm stating obvious, eval'ing file dangerous: user can embed [exec whatever wish] such file.
much better read "labels" , use giantic switch or hash map or whatever execute predetermined command. catching non-existing "labels" becomes non-issue.
Comments
Post a Comment