Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2003-05-13
03:36 • Ticket [734402ffff] catch fails to catch error status still Closed with 6 ot... artifact: 3554c920b5 user: msofer
2003-05-12
08:01 • Ticket [734402ffff]: 4 changes artifact: 5636689a5e user: nobody
2003-05-08
19:24 • Closed ticket [734402ffff]. artifact: de7ab19aaa user: msofer
11:23 • Open ticket [734402ffff]. artifact: 6fc01fb1f8 user: dgp
09:28 • Pending ticket [734402ffff]. artifact: 6f624bd878 user: msofer
01:47 • New ticket [734402ffff]. artifact: c8bf48b73f user: nobody

catch fails to catch error

Closed / Invalid734402ffffffffffffffffffffffffffffffffffCreated 24 years agoUpdated 24 years ago
Descriptionplain2003-05-08 01:47:32
catch [ error "This is an error"]
   Fails to catch to error in tcl 8.4.2.  In tcl 8.3,
this correctly caught
the error.  For this simple case, the obvious fix is:
catch { error "This is an error" }
However, the difference in behavior affects more
complex scripts.

     -John <[email protected]>
msoferplain2003-05-08 09:28:47
Logged In: YES 
user_id=148712

The described 8.4.2 behaviour is correct: 
   catch [ error "This is an error"] 
is semantically equivalent to
   set err [ error "This is an error"] 
   catch $err
as substitution occurs before the [catch] command is 
invoked; as substitution raises an error, [catch] is never 
actually invoked.

Did this really catch the error in 8.3? Could you please post 
the output of
   info patchlevel
in the corresponding interpreter?
dgpplain2003-05-08 11:23:47
Logged In: YES 
user_id=80530


See Bug 219184.  Fixed for Tcl 8.4a3.
msoferplain2003-05-08 19:24:19
Logged In: YES 
user_id=148712

Doh ... I did have a déjà-vu feeling.
nobodyplain2003-05-12 08:01:15
Logged In: NO 


  The behavior may be correct, but the man page for "catch"
does not indicate any distinction between "catch [ error ]" and 
"catch { error }".  I believe that, as a minimum, the
documentation of
"catch" should be corrected.
msoferplain2003-05-13 03:36:50
Logged In: YES 
user_id=148712

Ah, but this distinction has nothing to do with the [catch]
command - it is described in the Tcl man page Tcl.n, rule
[2]: when you invoke
   catch [error]
the error occurs during the substitution phase, *before*
[catch] is called (as it is, it never gets called).

Note also that the (buggy) behaviour in 8.3 was inconsistent:

% info patch
8.3.4
% catch [error]
1
% set c catch; $c [error]
wrong # args: should be "error message ?errorInfo? ?errorCode?"
Log in (anonymous is fine) to add a comment.