Re: try... query

Liste des GroupesRevenir à cl tcl 
Sujet : Re: try... query
De : wortkarg3 (at) *nospam* yahoo.com (Harald Oehlmann)
Groupes : comp.lang.tcl
Date : 06. Dec 2024, 15:22:28
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <viv1b3$26vb1$3@dont-email.me>
References : 1
User-Agent : Mozilla Thunderbird
Am 06.12.2024 um 14:11 schrieb Alan Grunwald:
1) I was assuming that if there was an error in do_various_other_stuff if would be caught by the inner 'on error' clause, which would delete obj2 and raise another error that would be caught by the outer 'on error' clause, which would delete obj1. Experiment suggests that this doesn't happen and the outer 'on error' clause isn't executed.
The return exits the procedure. So, the outer catch is not taken.
Instead, you may use the error command to do so. But keeping the original stack trace is difficult.

2) Originally, I wasn't including -errorinfo in the return statements in the 'on error' clauses, but I found that the stack trace didn't properly identify the line causing the error. Including -errorinfo seems to have cured that problem.
Yes, better use finally.

Q1) Have I misunderstood the way try... works, or is my problem elsewhere? I realise that I could do away with the nested try... statement and check whether obj1 and obj2 exist and only destroy them if they do, but that seems clunky.
I would use the finally and check for a flag. This works also with return.

Q2) Have I coded the return statements properly to get the error information to propagate correctly? I have a vague memory of doing it this way sometime in the past only for some other issue to emerge that I corrected by not using -errorinfo.
Better avoid it.
My proposal:
proc allocateResources {} {
     set obj1 [Some_mechanism]
     try {
         set obj2 [Some_other_mechanism]
         try {
             do_various_other_stuff
             # above, resource is cleared, so remove indicator
             unset obj2
             unset obj1
             # this may also go to the end of the procedure, no difference
             return [list $res1 $res2]
         } finally {
             if {[info exists obj2]} {
             $obj2 destroy
    }
}
     } finally {
         if {[info exists obj1]} {
            $obj1 destroy
}
     }
}

Date Sujet#  Auteur
6 Dec 24 * try... query11Alan Grunwald
6 Dec 24 +* Re: try... query2Harald Oehlmann
6 Dec 24 i`- Re: try... query1Alan Grunwald
6 Dec 24 +- Re: try... query1Harald Oehlmann
6 Dec 24 +- Re: try... query1Christian Gollwitzer
6 Dec 24 `* Re: try... query6Ralf Fassel
6 Dec 24  `* Re: try... query5Alan Grunwald
6 Dec 24   `* Re: try... query4Alan Grunwald
7 Dec 24    `* Re: try... query3Harald Oehlmann
8 Dec 24     `* Re: try... query2Alan Grunwald
8 Dec 24      `- Re: try... query1Petro Kazmirchuk

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal