What is actually the difference between raising an exception in TCL via return -code error ...and error ...? When would one be used instead of the other?
What is actually the difference between raising an exception in TCL via return -code
Share
The
errorcommand produces an error right at the current point; it’s great for the cases where you’re throwing a problem due to a procedure’s internal state.The
return -code errorcommand makes the procedure it is placed in produce an error (as if the procedure waserror); it’s great for the case where there’s a problem with the arguments passed to the procedure (i.e., the caller did something wrong).The difference really comes when you look at the stack trace.
Here’s a (contrived!) example: