home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / tkisrc04.zip / lib / tk / bgerror.tcl next >
Text File  |  1998-09-09  |  2KB  |  68 lines

  1. # bgerror.tcl --
  2. #
  3. # This file contains a default version of the bgerror procedure.  It
  4. # posts a dialog box with the error message and gives the user a chance
  5. # to see a more detailed stack trace.
  6. #
  7. # SCCS: @(#) bgerror.tcl 1.8 96/02/16 10:48:14
  8. #
  9. # Copyright (c) 1992-1994 The Regents of the University of California.
  10. # Copyright (c) 1994-1995 Sun Microsystems, Inc.
  11. #
  12. # See the file "license.terms" for information on usage and redistribution
  13. # of this file, and for a DISCLAIMER OF ALL WARRANTIES.
  14.  
  15. # bgerror --
  16. # This is the default version of bgerror.  It posts a dialog box containing
  17. # the error message and gives the user a chance to ask to see a stack
  18. # trace.
  19. # Arguments:
  20. # err -            The error message.
  21.  
  22. proc bgerror err {
  23.     global errorInfo
  24.     set info $errorInfo
  25.     set button [tk_dialog .bgerrorDialog "Error in Tcl Script" \
  26.         "Error: $err" error 0 OK "Skip Messages" "Stack Trace"]
  27.     if {$button == 0} {
  28.     return
  29.     } elseif {$button == 1} {
  30.     return -code break
  31.     }
  32.  
  33.     set w .bgerrorTrace
  34.     catch {destroy $w}
  35.     toplevel $w -class ErrorTrace
  36.     wm minsize $w 1 1
  37.     wm title $w "Stack Trace for Error"
  38.     wm iconname $w "Stack Trace"
  39.     button $w.ok -text OK -command "destroy $w"
  40.     text $w.text -relief sunken -bd 2 -yscrollcommand "$w.scroll set" \
  41.         -setgrid true -width 60 -height 20
  42.     scrollbar $w.scroll -relief sunken -command "$w.text yview"
  43.     pack $w.ok -side bottom -padx 3m -pady 2m
  44.     pack $w.scroll -side right -fill y
  45.     pack $w.text -side left -expand yes -fill both
  46.     $w.text insert 0.0 $info
  47.     $w.text mark set insert 0.0
  48.  
  49.     # Center the window on the screen.
  50.  
  51.     wm withdraw $w
  52.     update idletasks
  53.     set x [expr [winfo screenwidth $w]/2 - [winfo reqwidth $w]/2 \
  54.         - [winfo vrootx [winfo parent $w]]]
  55.     set y [expr [winfo screenheight $w]/2 - [winfo reqheight $w]/2 \
  56.         - [winfo vrooty [winfo parent $w]]]
  57.     wm geom $w +$x+$y
  58.     wm deiconify $w
  59.  
  60.     # Be sure to release any grabs that might be present on the
  61.     # screen, since they could make it impossible for the user
  62.     # to interact with the stack trace.
  63.  
  64.     if {[grab current .] != ""} {
  65.     grab release [grab current .]
  66.     }
  67. }
  68.