summaryrefslogtreecommitdiff
path: root/ice-9/error.scm
diff options
context:
space:
mode:
Diffstat (limited to 'ice-9/error.scm')
-rw-r--r--ice-9/error.scm37
1 files changed, 37 insertions, 0 deletions
diff --git a/ice-9/error.scm b/ice-9/error.scm
new file mode 100644
index 000000000..8da006d4f
--- /dev/null
+++ b/ice-9/error.scm
@@ -0,0 +1,37 @@
+;;; {Error Handling}
+;;;
+
+(module (ice-9 error)
+ (open (ice-9 guile)
+ ((ice-9 repl) save-stack))
+ (export error warn))
+
+(define (error . args)
+ (save-stack)
+ (if (null? args)
+ (scm-error 'misc-error #f "?" #f #f)
+ (let loop ((msg "%s")
+ (rest (cdr args)))
+ (if (not (null? rest))
+ (loop (string-append msg " %S")
+ (cdr rest))
+ (scm-error 'misc-error #f msg args #f)))))
+
+;; bad-throw is the hook that is called upon a throw to a an unhandled
+;; key (unless the throw has four arguments, in which case
+;; it's usually interpreted as an error throw.)
+;; If the key has a default handler (a throw-handler-default property),
+;; it is applied to the throw.
+;;
+(define (bad-throw key . args)
+ (apply error "unhandled-exception:" key args))
+
+
+(define (warn . stuff)
+ (with-output-to-port (current-error-port)
+ (lambda ()
+ (newline)
+ (display ";;; WARNING ")
+ (display stuff)
+ (newline)
+ (car (last-pair stuff))))) \ No newline at end of file