Based on the help page for the Tcl catch command, I was trying to use the specified result variables like TCL_OK or TCL_ERROR. However, there is some problem with the syntax of how those variables should be accessed. Does anyone have a code example that uses those variables instead of magic numbers?
3
votes
1 Answers
3
votes
From my experience, you want to use the numerical values, not the names. The names are used when programming in the C api but, from Tcl, one just uses the numbers.
set code [catch {
my script
} result]
switch -exact -- $code {
0 {
puts "normal command completion"
}
1 {
puts "code threw an error (ie: error 'wtf')"
}
2 {
puts "code used 'return' command normally"
}
3 {
puts "code used 'break' command"
}
4 {
puts "code used 'continue' command"
}
}