Forum OpenACS Development: Any way to get the tcl stack trace from try-catch?


I know there's a couple of procs on Open ACS for generating a tcl stack trace.

I was wondering if these procs will work in a try-catch code block where I'd want to print out the stack trace on the catch block.

If I'm not mistaken the stack trace would only print the tcl proc call stack of the try-catch and not the actual trace of where the problem happened. Can anyone confirm this?

Any ideas are appreciated. Thanks!

Why not try it and let us know?

Re-throwing a caught error in Tcl is easy, e.g.:

if { [catch {
   Do some stuff that breaks.
} errmsg] } {
   # We caught an unexpected error while the mutex was locked, so
   # unlock the mutex, then re-throw the error:
   ns_mutex unlock $my_mutex
   global errorInfo
   set my_error $errorInfo
   error $my_error
ns_mutex unlock $my_mutex

If you want to log the stack trace but not re-throw the error, look at that $errorInfo stuff. Perhaps Tcl or TclLib provide additional tools for manipulating it.

Posted by sep ng on
I'm sorry it's taken a long while to get back but just ran through some tests on this and yes, errorInfo contains all adequate information regarding the error the catch command caught. It's a great first step for what I want to do. Thanks a lot!