0

To grep the error on the screen though catch eg

   puts $c
   #error on terminal : can't read "c": no such variable

   catch {puts $c} err
   puts $err # value of err 1

Is there any way to catch actual error message in TCL apart from signal in variable err.

kostix
  • 51,517
  • 14
  • 93
  • 176
made_in_india
  • 2,109
  • 5
  • 40
  • 63

1 Answers1

3

Yes. Read the ::errorInfo or ::errorCode global variables to get the stack trace and a machine-parsable "POSIX error" three-element list, correspondingly.

Since Tcl 8.5, it's also possible to pass a name of a dictionary to catch after the name of the variable to receive the result, and that dictionary will be populated by much of what can be obtained via "classic" error variables I described above, and more.

This is all explained in the catch manual page.

kostix
  • 51,517
  • 14
  • 93
  • 176
  • 1
    In tcl 8.6 you even got the [`try`](http://www.tcl.tk/man/tcl8.6/TclCmd/try.htm) command, which can also be useful. The usage of `try` is easier than it looks (the usual `try {...} on error msg {puts $msg}`). Also note that Tcl builds unlike Java or .Net the error stack while unwinding. – Johannes Kuhn Mar 22 '13 at 20:08