93ce54d212bee450e605c02112ac869708414fbe
[software/python-on-guile.git] / modules / language / python / exceptions.scm
1 (define-module (language python exceptions)
2 #:use-module (oop pf-objects)
3 #:use-module (oop goops)
4 #:export (StopIteration GeneratorExit RuntimeError
5 Exception ValueError TypeError
6 IndexError KeyError AttributeError
7 SyntaxError SystemException
8 OSError ProcessLookupError PermissionError
9 None NotImplemented NotImplementedError
10 RunTimeError AssertionError ImportError
11 ModuleNotFoundError BlockingIOError))
12
13 (define-syntax-rule (aif it p x y) (let ((it p)) (if it x y)))
14
15 (define-python-class Exception ()
16 (define __init__
17 (case-lambda
18 ((self)
19 (values))
20 ((self val . l)
21 (set self 'value val))))
22
23 (define __repr__
24 (lambda (self)
25 (aif it (ref self 'value #f)
26 (format #f "~a:~a"
27 (ref self '__name__) it)
28 (format #f "~a"
29 (ref self '__name__))))))
30
31 (define-syntax define-er
32 (syntax-rules ()
33 ((_ nm k)
34 (define-python-class nm (Exception)))
35 ((_ nm w k)
36 (define-python-class nm w))))
37
38 (define StopIteration 'StopIteration)
39 (define GeneratorExit 'GeneratorExit)
40 (define-er SystemException 'SystemException)
41 (define-er RuntimeError 'RuntimeError)
42 (define-er IndexError 'IndexError)
43 (define-er ValueError 'ValueError)
44 (define None 'None)
45 (define-er KeyError 'KeyError)
46 (define-er TypeError 'TypeError)
47 (define-er AttributeError 'AttributeError)
48 (define-er SyntaxError 'SyntaxError)
49 (define-er OSError 'OSError)
50 (define-er ProcessLookupError 'ProcessLookupError)
51 (define-er PermissionError 'PermissionError)
52 (define-er NotImplementedError 'NotImplementedError)
53 (define-er RunTimeError 'RunTimeError)
54 (define AssertionError 'AssertionError)
55 (define-er ImportError 'ImportError)
56 (define-er ModuleNotFoundError (ImportError) 'ModuleNotFoundError)
57 (define-er BlockingIOError 'BlockingIOError)
58
59 (define NotImplemented (list 'NotImplemented))
60
61
62