summaryrefslogtreecommitdiff
path: root/modules/language/python/exceptions.scm
blob: 60b850e3da6a0787f9d469d3e2c8d944a6e70267 (about) (plain)
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
(define-module (language python exceptions)
  #:use-module (oop pf-objects)
  #:use-module (oop goops)
  #:export (StopIteration GeneratorExit RuntimeError
                          Exception ValueError TypeError
                          IndexError KeyError AttributeError
                          SyntaxError SystemException
                          OSError ProcessLookupError PermissionError
                          None NotImplemented NotImplementedError
			  RunTimeError AssertionError))

(define-syntax-rule (aif it p x y) (let ((it p)) (if it x y)))

(define StopIteration       'StopIteration)
(define GeneratorExit       'GeneratorExit)
(define SystemException     'SystemException)
(define RuntimeError        'RuntimeError)
(define IndexError          'IndexError)
(define ValueError          'ValueError)
(define None                'None)
(define KeyError            'KeyError)
(define TypeError           'TypeError)
(define AttributeError      'AttributeError)
(define SyntaxError         'SyntaxError)
(define OSError             'OSError)
(define ProcessLookupError  'ProcessLookupError)
(define PermissionError     'PermissionError)
(define NotImplementedError 'NotImplementedError)
(define RunTimeError        'RunTimeError)
(define AssertionError      'AssertionError)

(define-python-class Exception ()
  (define __init__
    (case-lambda
      ((self)
       (values))
      ((self val . l)
       (set self 'value val))))
                 
  (define __repr__
    (lambda (self)
      (aif it (ref self 'value #f)
           (format #f "~a:~a"
                   (ref self '__name__) it)
           (format #f "~a"
                   (ref self '__name__))))))


(define NotImplemented (list 'NotImplemented))