-
Notifications
You must be signed in to change notification settings - Fork 0
/
zperror.zp
36 lines (29 loc) · 1.01 KB
/
zperror.zp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
(define (exit-failure . code)
"end the program with status code 1 or a supplied error code.
params:
- code: the error code to use (optional)
complexity: O(1)
returns: this procedure ends the program"
(if (null? code) (exit 1) (exit (car code))))
(define (exit-success)
"end the program with status code 0.
complexity: O(1)
returns: this procedure ends the program"
(exit 0))
(define (error:from-string . strs)
"takes one or multiple strings (or objects coercible to strings)
and throws an error with it as message.
params:
- strs: the error message as one or more strings (will be joined with a space)
complexity: O(1)
returns: a thrown error"
(error:throw (make-error (string:join (map ->string strs) " "))))
(define (error:print-and-throw . args)
"prints an error to stderr and then throws it as an exception.
params:
- args: varagrs to print and throw
complexity: O(n)
returns: a thrown error"
(begin
(apply error args)
(apply error:from-string args)))