2003-03-10 21:47:38 -05:00
|
|
|
;; Copyright (c) 2001-2003 by Norbert Freudemann, David Frese
|
|
|
|
|
|
|
|
;; *** x errors ******************************************************
|
|
|
|
|
2001-12-19 16:37:16 -05:00
|
|
|
(define-record-type x-error :x-error
|
2003-03-10 21:47:38 -05:00
|
|
|
(make-x-error display serial code major-opcode minor-opcode resource-id text)
|
2001-12-19 16:37:16 -05:00
|
|
|
x-error?
|
2003-03-10 21:47:38 -05:00
|
|
|
(display x-error:display)
|
|
|
|
(serial x-error:serial)
|
|
|
|
(code x-error:code)
|
|
|
|
(major-opcode x-error:major-opcode)
|
|
|
|
(minor-opcode x-error:minor-opcode)
|
|
|
|
(resource-id x-error:resource-id)
|
|
|
|
(text x-error:text))
|
2001-12-19 16:37:16 -05:00
|
|
|
|
2003-03-10 21:47:38 -05:00
|
|
|
(define-exported-binding "scx-x-error" :x-error)
|
2001-12-19 16:37:16 -05:00
|
|
|
|
2003-03-10 21:47:38 -05:00
|
|
|
(define-enumerated-type error-code :error-code
|
|
|
|
error-code? error-codes error-code-name error-code-index
|
|
|
|
(success bad-request bad-value bad-window bad-pixmap bad-atom
|
|
|
|
bad-cursor bad-font bad-match bad-drawable bad-access bad-alloc
|
|
|
|
bad-color bad-gc bad-id-choice bad-name bad-length bad-implementation))
|
2001-12-19 16:37:16 -05:00
|
|
|
|
2003-03-10 21:47:38 -05:00
|
|
|
(define-exported-binding "scx-error-code" :error-code)
|
|
|
|
(define-exported-binding "scx-error-codes" error-codes)
|
2001-12-19 16:37:16 -05:00
|
|
|
|
2003-03-10 21:47:38 -05:00
|
|
|
;; *** error exceptions **********************************************
|
2001-12-19 16:37:16 -05:00
|
|
|
|
2003-03-10 21:47:38 -05:00
|
|
|
;; Call synchronize to have the exceptions signaled where they belong to.
|
2001-12-19 16:37:16 -05:00
|
|
|
|
2003-03-10 21:47:38 -05:00
|
|
|
(define (use-x-error-exceptions!)
|
|
|
|
(set-error-handler! (lambda (display error)
|
|
|
|
(error "x-exception: " display error)))) ;; TODO
|
2001-12-19 16:37:16 -05:00
|
|
|
|
2003-03-10 21:47:38 -05:00
|
|
|
;; *** error-queue ***************************************************
|
2001-12-19 16:37:16 -05:00
|
|
|
|
2003-03-10 21:47:38 -05:00
|
|
|
;; Interface:
|
|
|
|
;; (use-x-error-queue!) returns a thunk that returns the most recent queue
|
|
|
|
;; element.
|
|
|
|
;; (empty-x-error-queue? q) return #t only for the initial queue.
|
|
|
|
;; (next-x-error-queue q) returns the next queue element, blocks if necessary.
|
|
|
|
;; (x-error-queue:this q) returns the x-error of that queue.
|
|
|
|
|
|
|
|
(define (use-x-error-queue!) ;; exp
|
|
|
|
(let* ((most-recent-x-error-queue empty-x-error-queue)
|
|
|
|
(handler (lambda (display error)
|
|
|
|
(set-next-x-error-queue! most-recent-x-error-queue
|
|
|
|
(make-x-error-queue error))
|
|
|
|
(set! most-recent-x-error-queue
|
|
|
|
(next-x-error-queue most-recent-x-error-queue)))))
|
|
|
|
(set-error-handler! handler)
|
|
|
|
(lambda () most-recent-x-error-queue)))
|
|
|
|
|
|
|
|
(define-record-type x-error-queue :x-error-queue
|
|
|
|
(really-make-x-error-queue this next)
|
|
|
|
x-error-queue?
|
|
|
|
(this x-error-queue:this)
|
|
|
|
(next really-next-x-error-queue really-set-next-x-error-queue!))
|
2002-02-08 12:09:43 -05:00
|
|
|
|
2003-03-10 21:47:38 -05:00
|
|
|
(define (make-x-error-queue error)
|
|
|
|
(really-make-x-error-queue error (make-placeholder)))
|
|
|
|
|
|
|
|
(define empty-x-error-queue (make-x-error-queue #f))
|
|
|
|
(define (empty-x-error-queue? obj)
|
|
|
|
(eq? obj empty-x-error-queue))
|
|
|
|
|
|
|
|
(define (next-x-error-queue x-error-queue)
|
|
|
|
(placeholder-value (really-next-x-error-queue x-error-queue)))
|
|
|
|
|
|
|
|
(define (set-next-x-error-queue! x-error-queue next-x-error-queue)
|
|
|
|
(placeholder-set! (really-next-x-error-queue x-error-queue)
|
|
|
|
next-x-error-queue))
|
|
|
|
|
|
|
|
;; *** default error handlers ****************************************
|
|
|
|
|
|
|
|
(import-lambda-definition %set-error-handler (handler)
|
|
|
|
"scx_Set_Error_Handler")
|
|
|
|
|
|
|
|
(import-lambda-definition call-c-error-handler (pointer display event)
|
|
|
|
"scx_Call_C_Error_Handler")
|
|
|
|
|
|
|
|
(define (set-error-handler! handler)
|
|
|
|
(let ((res (%set-error-handler handler)))
|
|
|
|
(if (number? res)
|
|
|
|
(lambda (display event) (call-c-error-handler (res display event)))
|
|
|
|
res)))
|
|
|
|
|
|
|
|
(import-lambda-definition get-error-text (display code)
|
|
|
|
"scx_Get_Error_Text")
|
|
|
|
|
|
|
|
(import-lambda-definition get-error-database-text
|
|
|
|
(display name message default-string)
|
|
|
|
"scx_Get_Error_Database_Text")
|
|
|
|
|
|
|
|
;(import-lambda-definition %set-io-error-handler (handler)
|
|
|
|
; "scx_Set_IO_Error_Handler")
|
|
|
|
|
|
|
|
(define *x-fatal-error-handler* ;; TODO do it like above??
|
|
|
|
(lambda (display)
|
|
|
|
#f))
|
2001-08-29 10:44:15 -04:00
|
|
|
|
|
|
|
(define-exported-binding "internal-x-fatal-error-handler"
|
2003-03-10 21:47:38 -05:00
|
|
|
*x-fatal-error-handler*)
|
|
|
|
|
|
|
|
(define (set-io-error-handler handler)
|
|
|
|
(let ((old-handler *x-fatal-error-handler*))
|
|
|
|
(set! *x-fatal-error-handler* handler)
|
|
|
|
old-handler))
|