Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to exit and halt execution when we do "source filename.tcl"

718 views
Skip to first unread message

Koolrans

unread,
Mar 15, 2005, 6:17:54 PM3/15/05
to
Greetings,

I have a file named named implementedProcedures.tcl which contain 3
procedures. The 3 procs are init, add, sub which return an error if
something is wrong.

In another tcl file called tests.tcl , I use this 3 procs many times
one after another. So basically it looks like

source implementedProcedures.tcl
init ABC
add 4 5
sub 7 9
sub 10 4
add 3 9
add 15 7
.
.
.
.
.
.
.
.
.
. Now I want to stop the excution of the script and return to the tcl
shell if any of the proc was not successful. Is there are tcl command
which can do this. I want to stop execution in a way that I cannot
even use catch to recover from the error. This mean on tcl shell when
i do

%source tests.tcl

it should stop the execution when it hits and error. and return to the
shell. Currently I used error function, but I belive one can use
catch to handle it. Any pointers would be very helpful

Thanks a lot.

Koolrans

Gerald W. Lester

unread,
Mar 15, 2005, 10:25:50 PM3/15/05
to
Koolrans wrote:
> ... I want to stop execution in a way that I cannot
> even use catch to recover from the error. ...

To the best of my knowledge this is not possible and still have the catch
command available.

Of course you could just rename catch to {}.

--
+--------------------------------+---------------------------------------+
| Gerald W. Lester | "The man who fights for his ideals is |
| Gerald...@cox.net | the man who is alive." -- Cervantes |
+--------------------------------+---------------------------------------+

Ralf Fassel

unread,
Mar 16, 2005, 5:34:17 AM3/16/05
to
* "Koolrans" <kool...@gmail.com>

| I have a file named named implementedProcedures.tcl which contain 3
| procedures. The 3 procs are init, add, sub which return an error if
| something is wrong.
--<snip-snip>--

| . Now I want to stop the excution of the script and return to the tcl
| shell if any of the proc was not successful.
--<snip-snip>--

| it should stop the execution when it hits and error. and return to the
| shell.

Which shell are you referring in the last paragraph? If you mean the
commandline from which you invoked TCL, just use `exit 1' instead of
`error' in your procs. Not a nice approach if your procs are meant to
go into a library of some kind. If you mean the TCL shell, I don't
know any other means than `error'.

| Currently I used error function, but I belive one can use catch to
| handle it.

Yes, you can catch `error'. What is the problem with that?
Remember: any function in TCL (even `exit') can be renamed and do
something completely different, so your original goal is not possible
with a always-succeed guaranty.

R'

lvi...@gmail.com

unread,
Mar 17, 2005, 8:41:15 AM3/17/05
to

According to Koolrans <kool...@gmail.com>:
:. Now I want to stop the excution of the script and return to the tcl

:shell if any of the proc was not successful. Is there are tcl command
:which can do this. I want to stop execution in a way that I cannot
:even use catch to recover from the error. This mean on tcl shell when
:i do


catch is defined to always catch. So you would need to create your
own catch if you don't want it intervening.

Perhaps something like:

proc catch {args} {
eval $args
}

would work?
--
<URL: http://wiki.tcl.tk/ > MP3 ID tag repair < http://www.fixtunes.com/?C=17038 >
Even if explicitly stated to the contrary, nothing in this posting
should be construed as representing my employer's opinions.
<URL: mailto:lvi...@gmail.com > <URL: http://www.purl.org/NET/lvirden/ >

0 new messages