mirror of
https://github.com/justinethier/cyclone.git
synced 2025-05-19 05:39:17 +02:00
Added with-handler
This commit is contained in:
parent
77bc10b339
commit
18b4292e4f
2 changed files with 22 additions and 1 deletions
|
@ -119,6 +119,7 @@
|
|||
error
|
||||
raise
|
||||
raise-continuable
|
||||
with-handler
|
||||
with-exception-handler
|
||||
Cyc-add-exception-handler
|
||||
Cyc-remove-exception-handler
|
||||
|
@ -976,6 +977,20 @@
|
|||
(define (raise-continuable obj)
|
||||
((Cyc-current-exception-handler)
|
||||
(cons 'continuable (if (pair? obj) obj (list obj)))))
|
||||
;; A simpler exception handler based on the one from Bigloo:
|
||||
;; https://www-sop.inria.fr/indes/fp/Bigloo/doc/bigloo-17.html#g20889
|
||||
;(define (with-handler handler body)
|
||||
(define-syntax with-handler
|
||||
(er-macro-transformer
|
||||
(lambda (exp rename compare)
|
||||
`(call/cc
|
||||
(lambda (k)
|
||||
(with-exception-handler
|
||||
(lambda (obj)
|
||||
(,(cadr exp) obj)
|
||||
(k #t))
|
||||
(lambda ()
|
||||
,@(cddr exp))))))))
|
||||
(define (with-exception-handler handler thunk)
|
||||
(let ((result #f)
|
||||
(my-handler
|
||||
|
|
|
@ -46,7 +46,13 @@
|
|||
(define (loop)
|
||||
(let ((line (read-line)))
|
||||
(when (not (eof-object? line))
|
||||
(call/cc
|
||||
(with-handler
|
||||
(lambda (obj)
|
||||
(display `(Error processing line ,line details ,obj)))
|
||||
(display (convert-line line))
|
||||
(newline))
|
||||
|
||||
#;(call/cc
|
||||
(lambda (k)
|
||||
(with-exception-handler
|
||||
(lambda (obj)
|
||||
|
|
Loading…
Add table
Reference in a new issue