Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

Lack of skill dictates economy of style. -- Joey Ramone


devel / comp.lang.tcl / Re: trapping errors inside an event loop

SubjectAuthor
* trapping errors inside an event loopMark Tarver
+* Re: trapping errors inside an event loopRich
|`* Re: trapping errors inside an event loopGerald Lester
| `- Re: trapping errors inside an event loopChristian Gollwitzer
`- Re: trapping errors inside an event loopMark Tarver

1
trapping errors inside an event loop

<71e55876-a2c1-44af-b406-5fdb39ec1044n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=12863&group=comp.lang.tcl#12863

  copy link   Newsgroups: comp.lang.tcl
X-Received: by 2002:a05:620a:51d5:b0:783:e139:644b with SMTP id cx21-20020a05620a51d500b00783e139644bmr18941qkb.4.1706356571617;
Sat, 27 Jan 2024 03:56:11 -0800 (PST)
X-Received: by 2002:ac8:5a0e:0:b0:42a:74b8:d8ba with SMTP id
n14-20020ac85a0e000000b0042a74b8d8bamr95954qta.1.1706356571323; Sat, 27 Jan
2024 03:56:11 -0800 (PST)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!newsfeed.endofthelinebbs.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.tcl
Date: Sat, 27 Jan 2024 03:56:11 -0800 (PST)
Injection-Info: google-groups.googlegroups.com; posting-host=86.28.97.229; posting-account=kJbRXgoAAADVvCa8xCOuqxtZ-KSaXUAS
NNTP-Posting-Host: 86.28.97.229
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <71e55876-a2c1-44af-b406-5fdb39ec1044n@googlegroups.com>
Subject: trapping errors inside an event loop
From: dr.mtar...@gmail.com (Mark Tarver)
Injection-Date: Sat, 27 Jan 2024 11:56:11 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 1783
 by: Mark Tarver - Sat, 27 Jan 2024 11:56 UTC

I'm trying to trap errors inside an event loop. Here is the relevant code

proc enact {File} {
set Source [open $File r]
set Data [read $Source]
set Command [trim $Data]
overwrite $File
catch [eval $Command] err
if { $err != 0 } {
send [concat "(error " $err ")"] }
close $Source}

To test this I sent the invalid command 'what .b' rather than say 'button .b'.
I expected TCL/tk to send an error message using 'send' and continue the loop. However what happens is that the loop exits with an error message 'invalid command what' and on examination I found the message has been sent using 'send'. So in some sense it was caught and yet it was not caught because the loop exited. Puzzling.

Mark

Re: trapping errors inside an event loop

<up39qg$3egpf$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=12864&group=comp.lang.tcl#12864

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!rocksolid2!news.neodome.net!news.mixmin.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: ric...@example.invalid (Rich)
Newsgroups: comp.lang.tcl
Subject: Re: trapping errors inside an event loop
Date: Sat, 27 Jan 2024 16:08:48 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 44
Message-ID: <up39qg$3egpf$1@dont-email.me>
References: <71e55876-a2c1-44af-b406-5fdb39ec1044n@googlegroups.com>
Injection-Date: Sat, 27 Jan 2024 16:08:48 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="af3176d436ddb0be9a0d952d73411b55";
logging-data="3621679"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+uef8iG1Dqs2YetlL4+fQ1"
User-Agent: tin/2.6.1-20211226 ("Convalmore") (Linux/5.15.139 (x86_64))
Cancel-Lock: sha1:UJr3C9XBt6d7PS7yswC5zHaD6T8=
 by: Rich - Sat, 27 Jan 2024 16:08 UTC

Mark Tarver <dr.mtarver@gmail.com> wrote:
> I'm trying to trap errors inside an event loop. Here is the relevant code
>
> proc enact {File} {
> set Source [open $File r]
> set Data [read $Source]
> set Command [trim $Data]
> overwrite $File
> catch [eval $Command] err
> if { $err != 0 } {
> send [concat "(error " $err ")"] }
> close $Source}
>
> To test this I sent the invalid command 'what .b' rather than say
> 'button .b'.

> I expected TCL/tk to send an error message using 'send' and continue
> the loop. However what happens is that the loop exits with an error
> message 'invalid command what' and on examination I found the message
> has been sent using 'send'. So in some sense it was caught and yet
> it was not caught because the loop exited. Puzzling.

You are testing the error "message" against zero, but you get an
indication of error from catch from the return code of catch itself.

You want to do this:

if {[catch [eval $Command] result] != 0} {
...

or

set r [catch [eval $Command] result]
if {$r != 0} {
...

As it stands (i.e., as you've shown us the code) there is no event loop
running, so enact will run once each time it is called. And nothing
shows how it is being called.

You also omitted the 'app' name above from the send. You have the
"cmd" and "args" but no "app". So your [send] call is incorrect above.

Re: trapping errors inside an event loop

<PqatN.183052$yEgf.177720@fx09.iad>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=12865&group=comp.lang.tcl#12865

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!news.1d4.us!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx09.iad.POSTED!not-for-mail
MIME-Version: 1.0
User-Agent: Mozilla Thunderbird
Subject: Re: trapping errors inside an event loop
Content-Language: en-US
Newsgroups: comp.lang.tcl
References: <71e55876-a2c1-44af-b406-5fdb39ec1044n@googlegroups.com>
<up39qg$3egpf$1@dont-email.me>
From: Gerald.L...@gmail.com (Gerald Lester)
In-Reply-To: <up39qg$3egpf$1@dont-email.me>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Lines: 49
Message-ID: <PqatN.183052$yEgf.177720@fx09.iad>
X-Complaints-To: abuse@fastusenet.org
NNTP-Posting-Date: Sat, 27 Jan 2024 16:45:35 UTC
Organization: fastusenet - www.fastusenet.org
Date: Sat, 27 Jan 2024 10:45:34 -0600
X-Received-Bytes: 2354
 by: Gerald Lester - Sat, 27 Jan 2024 16:45 UTC

On 1/27/24 10:08, Rich wrote:
> Mark Tarver <dr.mtarver@gmail.com> wrote:
>> I'm trying to trap errors inside an event loop. Here is the relevant code
>>
>> proc enact {File} {
>> set Source [open $File r]
>> set Data [read $Source]
>> set Command [trim $Data]
>> overwrite $File
>> catch [eval $Command] err
>> if { $err != 0 } {
>> send [concat "(error " $err ")"] }
>> close $Source}
>>
>> To test this I sent the invalid command 'what .b' rather than say
>> 'button .b'.
>
>> I expected TCL/tk to send an error message using 'send' and continue
>> the loop. However what happens is that the loop exits with an error
>> message 'invalid command what' and on examination I found the message
>> has been sent using 'send'. So in some sense it was caught and yet
>> it was not caught because the loop exited. Puzzling.
>
> You are testing the error "message" against zero, but you get an
> indication of error from catch from the return code of catch itself.
>
> You want to do this:
>
> if {[catch [eval $Command] result] != 0} {
> ...
>
> or
>
> set r [catch [eval $Command] result]
> if {$r != 0} {
> ...
>
>
> As it stands (i.e., as you've shown us the code) there is no event loop
> running, so enact will run once each time it is called. And nothing
> shows how it is being called.
>
> You also omitted the 'app' name above from the send. You have the
> "cmd" and "args" but no "app". So your [send] call is incorrect above.
>

Actually, you don't want [eval $Command] -- you just want $Command

Re: trapping errors inside an event loop

<up3dj3$3f6vu$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=12866&group=comp.lang.tcl#12866

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!news.niel.me!news.gegeweb.eu!gegeweb.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: aurio...@gmx.de (Christian Gollwitzer)
Newsgroups: comp.lang.tcl
Subject: Re: trapping errors inside an event loop
Date: Sat, 27 Jan 2024 18:13:07 +0100
Organization: A noiseless patient Spider
Lines: 44
Message-ID: <up3dj3$3f6vu$1@dont-email.me>
References: <71e55876-a2c1-44af-b406-5fdb39ec1044n@googlegroups.com>
<up39qg$3egpf$1@dont-email.me> <PqatN.183052$yEgf.177720@fx09.iad>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Sat, 27 Jan 2024 17:13:07 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="7c18d6cffd0c486fbc3d4b45b37050e7";
logging-data="3644414"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19bbl7qt7u90gBGaXxD+YIrGU7Rz0BTJks="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:+9vqJ885nV2x5sG0hNDp6Sm/DvM=
In-Reply-To: <PqatN.183052$yEgf.177720@fx09.iad>
 by: Christian Gollwitzer - Sat, 27 Jan 2024 17:13 UTC

Am 27.01.24 um 17:45 schrieb Gerald Lester:
> On 1/27/24 10:08, Rich wrote:
>> Mark Tarver <dr.mtarver@gmail.com> wrote:
>>> I'm trying to trap errors inside an event loop.  Here is the relevant
>>> code
>>>
>>> proc enact {File} {
>>>    set Source [open $File r]
>>>    set Data [read $Source]
>>>    set Command [trim $Data]
>>>    overwrite $File
>>>    catch [eval $Command] err
>>>    if { $err != 0 } {
>>         ...
> Actually, you don't want [eval $Command] -- you just want $Command

To put it together: The correct invocation would be:

if {[catch $Command result]} {
# an error has happened
# the error message is in $result
} else {
# it went smoothly
# the reult of $Command is in $result
}

Catch executes the 1st arg, i.e.

catch $Command result

is the same as

set result [eval $Command]

- with the difference that it catches the errors.

Also note that the command is executed in the current scope. I.e. if
Command is "set a 3", then the variable a inside the proc enact will be
set. Most systems that execute such commands, e.g. Tk button commands
etc., rather use the global level via

catch {uplevel #0 $Command}

Christian

Re: trapping errors inside an event loop

<c6eb8ee6-6ec2-4f6c-b69e-8254acd17338n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=12869&group=comp.lang.tcl#12869

  copy link   Newsgroups: comp.lang.tcl
X-Received: by 2002:a05:620a:400b:b0:784:24d7:994 with SMTP id h11-20020a05620a400b00b0078424d70994mr21578qko.6.1706612807385;
Tue, 30 Jan 2024 03:06:47 -0800 (PST)
X-Received: by 2002:a05:620a:3b0f:b0:784:8c3:9fce with SMTP id
tl15-20020a05620a3b0f00b0078408c39fcemr34716qkn.6.1706612807214; Tue, 30 Jan
2024 03:06:47 -0800 (PST)
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.tcl
Date: Tue, 30 Jan 2024 03:06:46 -0800 (PST)
In-Reply-To: <71e55876-a2c1-44af-b406-5fdb39ec1044n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=86.28.97.229; posting-account=kJbRXgoAAADVvCa8xCOuqxtZ-KSaXUAS
NNTP-Posting-Host: 86.28.97.229
References: <71e55876-a2c1-44af-b406-5fdb39ec1044n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <c6eb8ee6-6ec2-4f6c-b69e-8254acd17338n@googlegroups.com>
Subject: Re: trapping errors inside an event loop
From: dr.mtar...@gmail.com (Mark Tarver)
Injection-Date: Tue, 30 Jan 2024 11:06:47 +0000
Content-Type: text/plain; charset="UTF-8"
 by: Mark Tarver - Tue, 30 Jan 2024 11:06 UTC

That's great; the program is working now. Thanks to all.

Mark

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor