Skip to content
Tcl Source Code View Ticket
Login

View Ticket

improve [break] error strack trace

Closed / Accepted536955ffffffffffffffffffffffffffffffffffCreated 25 years agoUpdated 25 years ago
Descriptionplain2002-03-29 23:50:10
% info patch
8.3.4
% proc mybreak {} {return -code break}
% catch mybreak
3
% proc breaktest {} {mybreak}
% list [catch breaktest msg] $msg
1 {invoked "break" outside of a loop}
% proc lucky {} {return -code 7}
% catch lucky
7
% proc luckytest {} {lucky}
% list [catch luckytest msg] $msg
7 {}

It would be more consistent if the only way
to pass back a non-TCL_OK, non-TCL_ERROR
return code from a proc was by using the
[return -code] command itself.

I'd rather see:

% list [catch luckytest msg] $msg
1 {command returned bad code: 7}
dgpplain2002-03-30 06:52:53
Logged In: YES 
user_id=80530

A related problem:

% proc test {} {
        # Imagine hundreds of lines here
        break
        # And hundreds more
}
% test
invoked "break" outside of a loop
% set errorInfo
invoked "break" outside of a loop
    while executing
"test"


Would be much better if ProcessProcResultCode
not only converted TCL_BREAK -> TCL_ERROR, but
also added good context to the ErrorInfo.
dgpplain2002-03-30 07:13:02
File Added - 20299: proc.patch

Logged In: YES 
user_id=80530

Here's a patch that does both things.
dgpplain2002-03-30 07:15:46
File Deleted - 20299: 



File Added - 20300: proc.patch

Logged In: YES 
user_id=80530

D'oh!  Let's try that patch again...
dgpplain2002-03-30 07:26:31
File Added - 20301: proc.patch2

Logged In: YES 
user_id=80530

updated patch contains changes to test suite too
msoferplain2002-03-30 09:19:53
Logged In: YES 
user_id=148712

I'm not sure about this one: it could break a lot of user
code, and destroy functionality that I think is valuable.
In particular, custom exception handling code may depend on
the return code being passed up the stack, without requiring
every intervening command to catch/rethrow the exception
code. 
This would force such code to either catch/rethrow at each
stage, or else to do receive a TCL_ERROR and pass the
exception type in a different manner - quite an expensive
proposition (see the latest catch.bench in tclbench).
dgpplain2002-03-31 00:31:39
Logged In: YES 
user_id=80530

After sleeping on  it, I agree that the inconsistency
argument doesn't make sense.  Yes, [return -code 7] is
inconsistent with [return -code break], but it is 
consistent with [return -code error].  One had to be
chosen, and the choice is already made and should not
be changed now.

I think I've heard of some people defining an "exit"
return code to give them a way to exit their program.
That usage needs the "exception-like" behavior of
extended return codes.

What do you think about the improved stack trace for
[break] and [continue] errors though?
dgpplain2002-04-06 04:52:25
File Deleted - 20301: 



File Added - 20639: proc.patch3

Logged In: YES 
user_id=80530

Here's an updated patch that only improves the stack
trace for [break] and [continue].
msoferplain2002-04-16 00:45:54
Logged In: YES 
user_id=148712

Committed the improved stack trace patch.
Log in (anonymous is fine) to add a comment.

Attachments: