3 ;;; Mes --- Maxwell Equations of Software
4 ;;; Copyright © 2016,2018 Jan Nieuwenhuizen <janneke@gnu.org>
6 ;;; This file is part of Mes.
8 ;;; Mes is free software; you can redistribute it and/or modify it
9 ;;; under the terms of the GNU General Public License as published by
10 ;;; the Free Software Foundation; either version 3 of the License, or (at
11 ;;; your option) any later version.
13 ;;; Mes is distributed in the hope that it will be useful, but
14 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
15 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ;;; GNU General Public License for more details.
18 ;;; You should have received a copy of the GNU General Public License
19 ;;; along with Mes. If not, see <http://www.gnu.org/licenses/>.
21 (mes-use-module (mes let))
22 (mes-use-module (mes fluids))
24 (define %eh (make-fluid
26 (if (defined? 'simple-format)
27 (simple-format (current-error-port) "unhandled exception:~a:~a\n" key args)
29 (display "unhandled exception:" (current-error-port))
30 (display key (current-error-port))
31 (display ":" (current-error-port))
32 (display args (current-error-port))
33 (newline (current-error-port))))
36 (define (catch key thunk handler)
37 (let ((previous-eh (fluid-ref %eh)))
45 (let ((handler (if (or (eq? key #t) (eq? key k)) handler
49 (apply handler (cons k args)))))))
52 (define (throw key . args)
53 (let ((handler (fluid-ref %eh)))
54 (apply handler (cons key args))))
56 (define with-throw-handler catch) ; FIXME: hack for Nyacc 0.75