-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
with-exception-handler
updated, new functions
`error-object?` and `error-object-message`
- Loading branch information
1 parent
1b413bd
commit ad91de6
Showing
7 changed files
with
121 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
(import (scheme repl)) | ||
|
||
; ------------------------------------------------ | ||
; you can't handle compile-time arity errors, like: | ||
; 1. direct invalid primop calls | ||
; - (cons 1), (car), (clock 1 2 3 4), etc. | ||
; 2. wrong "let" recursions | ||
; - (let loop ((x 1)) (loop 1 2 3 4)) | ||
; 3. direct lambda calls | ||
; - ((lambda (x) x) 1 2 3) | ||
; - ((lambda (x y . z) x) 1) | ||
|
||
; but you can handle runtime arity errors | ||
|
||
; - wrong "let" recursions | ||
(with-exception-handler | ||
(lambda (x) | ||
(print "error detected. " x) | ||
(if (error-object? x) | ||
(print " " (error-object-message x)))) | ||
(lambda () | ||
(let loop ((x 1)) | ||
(define q loop) | ||
(q 1 2 3)) | ||
)) | ||
|
||
; - direct lambda calls | ||
(define f (lambda (x) 777)) | ||
|
||
(with-exception-handler | ||
(lambda (x) | ||
(print "error detected. " x) | ||
(if (error-object? x) | ||
(print " " (error-object-message x)))) | ||
(lambda () | ||
(f 1 2 3) | ||
)) | ||
|
||
; - case-lambdas | ||
(define g (case-lambda | ||
((a) 1) | ||
((a b) 2) | ||
((a b c d . e) 4) )) | ||
|
||
(with-exception-handler | ||
(lambda (x) | ||
(print "error detected. " x) | ||
(if (error-object? x) | ||
(print " " (error-object-message x)))) | ||
(lambda () | ||
(g 1 2 3) | ||
)) | ||
|
||
; - olvm critical errors (error class is 'crash) | ||
(with-exception-handler | ||
(lambda (x) | ||
(print "error detected. " x) | ||
(if (error-object? x) | ||
(print " " (error-object-message x)))) | ||
(lambda () | ||
; don't repeat, this is a dirty hack! | ||
((vm:cast (bytevector 0) type-bytecode) 1 2 3) | ||
)) | ||
|
||
; - manual errors | ||
(with-exception-handler | ||
(lambda (x) | ||
(print "error detected. " x) | ||
(if (error-object? x) | ||
(print " " (error-object-message x)))) | ||
(lambda () | ||
(raise "hello, i'm error!") | ||
)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
error detected. #(error 17 #<lambda> 3) | ||
(error 17 -> (wrong number of arguments: 3, but #<lambda> expects 1)) | ||
error detected. #(error 17 #<lambda> 3) | ||
(error 17 -> (wrong number of arguments: 3, but #<f> expects 1)) | ||
error detected. #(error 17 #<lambda> 3) | ||
(error 17 -> (wrong number of arguments: 3, but #<g> expects one of #(1 2 (at least 4)))) | ||
error detected. #(crash 0 #<lambda> 0) | ||
(error 0 -> (unsupported vm code #<lambda>)) | ||
error detected. hello, i'm error! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,4 +3,5 @@ | |
3 | ||
3 | ||
3 | ||
error detected. (What is 'not-a-func'?) | ||
error detected. | ||
(eval failed with (What is 'not-a-func'?)) |