Re: try... query

Liste des GroupesRevenir à cl tcl 
Sujet : Re: try... query
De : ralfixx (at) *nospam* gmx.de (Ralf Fassel)
Groupes : comp.lang.tcl
Date : 06. Dec 2024, 18:59:51
Autres entêtes
Message-ID : <ygaed2k8zfs.fsf@akutech.de>
References : 1
User-Agent : Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
* Alan Grunwald <nospam.nurdglaw@gmail.com>
| proc allocateResources {} {
|     set obj1 [Some_mechanism]
|     try {
|         set obj2 [Some_other_mechanism]
|         try {
|             do_various_other_stuff
|         } on error {message errorDict} {
|             $obj2 destroy
|             return                                          \
|                 -code error                                 \
|                 -errorcode [dict get $errorDict -errorcode] \
|                 -errorinfo [dict get $errorDict -errorinfo] \
|                 $message
|         }

As Harald pointed out, 'finally' is the way to go here (even if the
"if exist" is clunky :-).

I just wanted to point out that you could use the errorDict directly, as in

  try {
    ...
  } on error {msg opts} {
    ...
    return -options $opts $msg
  }

instead of extracting errorinfo and errorcode manually, and if I use
that form, I get the expected behaviour:

    proc foo {} {
        try {
            puts "level 1"
            try {
                puts "level 2"
                error "err level 2"
            } on error {msg opts} {
                puts "error in level 2"
                return -options $opts $msg
            }
        } on error {msg opts} {
            puts "error in level 1"
            return -options $opts $msg
        }
    }
   
    % catch foo
    level 1
    level 2
    error in level 2
    error in level 1
    1
   
    % set errorInfo
    err level 2
        while executing
    "error "err level 2""
        (procedure "foo" line 6)
        invoked from within
    "foo"

HTH
R'

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