bgerror, app error, I'm new... 
Author Message
 bgerror, app error, I'm new...

Here is the code:

 proc setDatasetID { w } {

    global datasetID
    set boofoo 0
    set datasetID [eval $w]
    if {[catch {after 2000 {eventMsg "Dataset ID: $datasetID" "" }}
boofoo ]} {
        logMsg "$boofoo" "ERROR"
        }
 }

Since the "eventMsg" procedure is expecting only one parameter, this raises
an error. However, the error comes up with the "Application error" message
box, not the "logMsg" error, that it should go to based on the catch,
right??

When I remove the extra parameter, the "eventMsg" routine accurately runs,
and the "logMsg" is ignored.

This leads me to the next question - is this a bgerror issue? Should I be
trapping this with bgerror, or some other built-in tcl or tk function? If
yes, could you provide me an example?

Thanks in advance. This newsgroup is a real lifesaver!
Don



Sat, 24 Jul 2004 20:30:52 GMT  
 bgerror, app error, I'm new...

Quote:

> Here is the code:

>  proc setDatasetID { w } {

>     global datasetID
>     set boofoo 0
>     set datasetID [eval $w]
>     if {[catch {after 2000 {eventMsg "Dataset ID: $datasetID" "" }}
> boofoo ]} {
>         logMsg "$boofoo" "ERROR"
>         }
>  }

> Since the "eventMsg" procedure is expecting only one parameter, this raises
> an error. However, the error comes up with the "Application error" message
> box, not the "logMsg" error, that it should go to based on the catch,
> right??

The problem here is the [after 2000] bit. This says: add the following
command as an event and when it's timer is up (i.e. in at least 2000 ms)
try to execute it. [after] in this form returns immediately with a clean
error code, so catch won't fire, and your logMsg won't be called. 2000
ms later, Tcl executes the erroneous command and needs to report an
error, however the rest of the code has moved on, so where should the
error go? Answer: call the "bgerror" proc and let it try and handle the
error.

Quote:

> When I remove the extra parameter, the "eventMsg" routine accurately runs,
> and the "logMsg" is ignored.

> This leads me to the next question - is this a bgerror issue? Should I be
> trapping this with bgerror, or some other built-in tcl or tk function? If
> yes, could you provide me an example?

Redefine bgerror to deal with these errors - for instance, put a call to
logMsg in there.

- Show quoted text -

Quote:

> Thanks in advance. This newsgroup is a real lifesaver!
> Don



Sat, 24 Jul 2004 20:54:10 GMT  
 bgerror, app error, I'm new...
Neil, thanks very much. I added this to the code, and it caught it:

proc bgerror explanation {

    logMsg "$explanation" "backgroundERROR"
 }

So now, when I get any background error, this will write it to my error log.

Thanks for the help,
Don


Quote:

> > Here is the code:

> >  proc setDatasetID { w } {

> >     global datasetID
> >     set boofoo 0
> >     set datasetID [eval $w]
> >     if {[catch {after 2000 {eventMsg "Dataset ID: $datasetID" "" }}
> > boofoo ]} {
> >         logMsg "$boofoo" "ERROR"
> >         }
> >  }

> > Since the "eventMsg" procedure is expecting only one parameter, this
raises
> > an error. However, the error comes up with the "Application error"
message
> > box, not the "logMsg" error, that it should go to based on the catch,
> > right??

> The problem here is the [after 2000] bit. This says: add the following
> command as an event and when it's timer is up (i.e. in at least 2000 ms)
> try to execute it. [after] in this form returns immediately with a clean
> error code, so catch won't fire, and your logMsg won't be called. 2000
> ms later, Tcl executes the erroneous command and needs to report an
> error, however the rest of the code has moved on, so where should the
> error go? Answer: call the "bgerror" proc and let it try and handle the
> error.

> > When I remove the extra parameter, the "eventMsg" routine accurately
runs,
> > and the "logMsg" is ignored.

> > This leads me to the next question - is this a bgerror issue? Should I
be
> > trapping this with bgerror, or some other built-in tcl or tk function?
If
> > yes, could you provide me an example?

> Redefine bgerror to deal with these errors - for instance, put a call to
> logMsg in there.

> > Thanks in advance. This newsgroup is a real lifesaver!
> > Don



Sat, 24 Jul 2004 21:16:22 GMT  
 bgerror, app error, I'm new...

Quote:

> Here is the code:

>  proc setDatasetID { w } {

>     global datasetID
>     set boofoo 0
>     set datasetID [eval $w]
>     if {[catch {after 2000 {eventMsg "Dataset ID: $datasetID" "" }}
> boofoo ]} {
>         logMsg "$boofoo" "ERROR"
>         }
>  }

> Since the "eventMsg" procedure is expecting only one parameter, this raises
> an error. However, the error comes up with the "Application error" message
> box, not the "logMsg" error, that it should go to based on the catch,
> right??

> When I remove the extra parameter, the "eventMsg" routine accurately runs,
> and the "logMsg" is ignored.

> This leads me to the next question - is this a bgerror issue? Should I be
> trapping this with bgerror, or some other built-in tcl or tk function? If
> yes, could you provide me an example?

Yes this is a bgerror because of the use of the after.

If you catch the eventMsg call directly it will work like you expected. But
the catch is around the after command which works fine (i.e. is schedules
some script to be run in 2 seconds) and the program goes back into
the event loop and the after event "fires" when the time is up and the script
is evaluated then - causing the error. But since it isn't inside your call stack
anymore it is handled by the bgerror routine.

Why are you using after? If you skip the call to after then everything can be handled
via a simple catch around your calls (in this case since the error is a typo in the code
I would suggest correcting that ;-)  Also you might want a catch around your call to
eval since that is running some arbitrary script that could also fail.

Bruce



Sat, 24 Jul 2004 21:15:55 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. expect: bgerror failed to handle background error.

2. Catching errors at [vwait] instead of [bgerror]

3. Tk's bgerror hangs - an innocent bug of Tk8.3.0

4. bgerror in windows from `wish myScript.tcl'

5. New error compiling 16bit app

6. App on new Machine Won't Compile

7. Exception error: can't start my app

8. Hash.new(Hash.new) doesn't use Hash.new as default value

9. APP Open error 11: Parameter typing error

10. APP Broker Error: Error socket() failed(10047)

11. Erratic internal error 1210 in clipper 5.2e app using DBFCDX - Error (0/1)

12. Erratic internal error 1210 in clipper 5.2e app using DBFCDX - Error (1/1)

 

 
Powered by phpBB® Forum Software