classtclcatch-block

check if a class is defined in TCL OO, not using catch



I have a code, and I want to make sure that a class definion is indeed loaded. Lets say that the class name is foo. I can do the following:
if { [ catch { foo new } ] } { source "path_to_code" }
Is there a way to do it without catch?

Solution

  • You can use the info command:

    if {![info object isa class foo]} {source "path_to_code"}