(define-module (language python exceptions) #:use-module (oop pf-objects) #:use-module (oop goops) #:export (StopIteration GeneratorExit RuntimeError Exception ValueError TypeError IndexError KeyError AttributeError ArgumentError SyntaxError SystemException OSError ProcessLookupError PermissionError None NotImplemented NotImplementedError RunTimeError AssertionError ImportError ModuleNotFoundError BlockingIOError InterruptedError BaseException ZeroDivisionError ArithmeticError OverflowError RecursionError Warning DeprecationWarning BytesWarning ResourceWarning UnicodeDecodeError LookupError IndentationError KeyboardInterrupt MemoryError NameError EOFError UnicodeError FileExistsError FileNotFoundError IsADirectoryError )) (define-syntax-rule (aif it p x y) (let ((it p)) (if it x y))) (define-python-class Exception () (define __init__ (case-lambda ((self) (values)) ((self val . l) (set self 'value val)))) (define __repr__ (lambda (self) (aif it (rawref self 'value #f) (format #f "~a:~a" (rawref self '__name__) it) (format #f "~a" (rawref self '__name__)))))) (define-python-class Warning () (define __init__ (case-lambda ((self) (values)) ((self val . l) (set self 'value val)))) (define __repr__ (lambda (self) (aif it (rawref self 'value #f) (format #f "~a:~a" (rawref self '__name__) it) (format #f "~a" (rawref self '__name__)))))) (define-syntax define-er (syntax-rules () ((_ nm k) (define-python-class nm (Exception))) ((_ nm w k) (define-python-class nm w)))) (define-syntax define-er2 (syntax-rules () ((_ nm k) (define-python-class nm (BaseException))) ((_ nm w k) (define-python-class nm w)))) (define StopIteration 'StopIteration) (define GeneratorExit 'GeneratorExit) (define-er FileExistsError 'FileExistsError) (define-er FileNotFoundError 'FileNotFoundError) (define-er IsADirectoryError 'IsADirectoryError) (define-er UnicodeError 'UnicodeError) (define-er EOFError 'EOFError) (define-er MemoryError 'MemoryError) (define-er NameError 'NameError) (define-er UnicodeDecodeError 'UnicodeDecodeError) (define-er LookupError 'LookupError) (define-er IndentationError 'IndentationError) (define-er OverflowError 'OverflowError) (define-er KeyboardInterrupt 'KeyboardInterrupt) (define-er RecursionError 'RecursionError) (define-er ArithmeticError 'ArithmeticError) (define-er BaseException 'BaseException) (define-er ZeroDivisionError 'ZeroDivisionError) (define-er SystemException 'SystemException) (define-er RuntimeError 'RuntimeError) (define-er IndexError 'IndexError) (define-er ArgumentError 'IndexError) (define-er ValueError 'ValueError) (define None 'None) (define-er KeyError 'KeyError) (define-er TypeError 'TypeError) (define-er AttributeError 'AttributeError) (define-er SyntaxError 'SyntaxError) (define-er OSError 'OSError) (define-er ProcessLookupError 'ProcessLookupError) (define-er PermissionError 'PermissionError) (define-er NotImplementedError 'NotImplementedError) (define-er RunTimeError 'RunTimeError) (define AssertionError 'AssertionError) (define-er ImportError 'ImportError) (define-er ModuleNotFoundError (ImportError) 'ModuleNotFoundError) (define-er BlockingIOError 'BlockingIOError) (define-er InterruptedError 'OSError) (define NotImplemented (list 'NotImplemented)) (define-syntax define-wr (syntax-rules () ((_ nm k) (define-python-class nm (Warning))) ((_ nm w k) (define-python-class nm w)))) (define-wr BytesWarning 'BytesWarning) (define-wr DepricationWarning 'DeprecationWarning) (define-wr ResourceWarning 'ResourceWarning)