removed unstable/exn (moved code to single use in web-server)
This commit is contained in:
parent
f21b871760
commit
e4e89b0bc9
|
@ -1,12 +0,0 @@
|
||||||
#lang racket
|
|
||||||
|
|
||||||
(require rackunit rackunit/text-ui unstable/exn "helpers.rkt")
|
|
||||||
|
|
||||||
(run-tests
|
|
||||||
(test-suite "exn.rkt"
|
|
||||||
(test-suite "try"
|
|
||||||
(test-ok (try (+ 1 2)))
|
|
||||||
(test-bad (try (+ 'a 'b)))
|
|
||||||
(test-ok (try (+ 'a 'b) (+ 3 4)))
|
|
||||||
(test-ok (try (+ 1 2) (+ 'a 'b)))
|
|
||||||
(test-bad (try (+ 'a 'b) (+ 'c 'd))))))
|
|
|
@ -1,32 +0,0 @@
|
||||||
#lang racket/base
|
|
||||||
(require racket/contract/base
|
|
||||||
(for-syntax racket/base))
|
|
||||||
|
|
||||||
;; network-error: symbol string . values -> void
|
|
||||||
;; throws a formatted exn:fail:network
|
|
||||||
(define (network-error src fmt . args)
|
|
||||||
(raise (make-exn:fail:network (format "~a: ~a" src (apply format fmt args))
|
|
||||||
(current-continuation-marks))))
|
|
||||||
|
|
||||||
;; exn->string : (or/c exn any) -> string
|
|
||||||
(define (exn->string exn)
|
|
||||||
(if (exn? exn)
|
|
||||||
(parameterize ([current-error-port (open-output-string)])
|
|
||||||
((error-display-handler) (exn-message exn) exn)
|
|
||||||
(get-output-string (current-error-port)))
|
|
||||||
(format "~s\n" exn)))
|
|
||||||
;; Eli: (or/c exn any)??
|
|
||||||
|
|
||||||
(define-syntax (try stx)
|
|
||||||
(syntax-case stx ()
|
|
||||||
[(_ e) #'(#%expression e)]
|
|
||||||
[(_ e0 e ...)
|
|
||||||
(syntax/loc stx
|
|
||||||
(with-handlers* ([exn:fail? (lambda (x) (try e ...))])
|
|
||||||
(#%expression e0)))]))
|
|
||||||
|
|
||||||
(provide try)
|
|
||||||
|
|
||||||
(provide/contract
|
|
||||||
[network-error (->* [symbol? string?] [] #:rest list? void?)]
|
|
||||||
[exn->string (-> any/c string?)])
|
|
|
@ -1,47 +0,0 @@
|
||||||
#lang scribble/manual
|
|
||||||
@(require scribble/eval "utils.rkt"
|
|
||||||
(for-label unstable/exn racket/contract racket/base))
|
|
||||||
|
|
||||||
@(define the-eval (make-base-eval))
|
|
||||||
@(the-eval '(require unstable/exn))
|
|
||||||
|
|
||||||
@title[#:tag "exn"]{Exceptions}
|
|
||||||
|
|
||||||
@defmodule[unstable/exn]
|
|
||||||
|
|
||||||
@unstable-header[]
|
|
||||||
|
|
||||||
@defproc[(network-error [s symbol?]
|
|
||||||
[fmt string?]
|
|
||||||
[v any/c] ...)
|
|
||||||
void]{
|
|
||||||
Like @racket[error], but throws a @racket[exn:fail:network].
|
|
||||||
}
|
|
||||||
|
|
||||||
@defproc[(exn->string [exn (or/c exn? any/c)])
|
|
||||||
string?]{
|
|
||||||
Formats @racket[exn] with @racket[(error-display-handler)] as a string.
|
|
||||||
}
|
|
||||||
|
|
||||||
@addition[@author+email["Carl Eastlund" "cce@racket-lang.org"]]
|
|
||||||
|
|
||||||
@defform[(try expr ...+)]{
|
|
||||||
|
|
||||||
Executes the first expression @racket[expr] in the sequence, producing its
|
|
||||||
result value(s) if it returns any. If it raises an exception instead,
|
|
||||||
@racket[try] continues with the next @racket[expr]. Exceptions raised by
|
|
||||||
intermediate expressions are reported to the @tech[#:doc '(lib
|
|
||||||
"scribblings/reference/reference.scrbl")]{current logger} at the @racket['debug]
|
|
||||||
level before continuing. Exceptions raised by the final expression are not
|
|
||||||
caught by @racket[try].
|
|
||||||
|
|
||||||
@defexamples[
|
|
||||||
#:eval the-eval
|
|
||||||
(try (+ 1 2) (+ 3 4))
|
|
||||||
(try (+ 'one 'two) (+ 3 4))
|
|
||||||
(try (+ 'one 'two) (+ 'three 'four))
|
|
||||||
]
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@(close-eval the-eval)
|
|
|
@ -78,7 +78,6 @@ Keep documentation and tests up to date.
|
||||||
@include-section["prop-contract.scrbl"]
|
@include-section["prop-contract.scrbl"]
|
||||||
@include-section["debug.scrbl"]
|
@include-section["debug.scrbl"]
|
||||||
@include-section["define.scrbl"]
|
@include-section["define.scrbl"]
|
||||||
@include-section["exn.scrbl"]
|
|
||||||
@include-section["file.scrbl"]
|
@include-section["file.scrbl"]
|
||||||
@include-section["find.scrbl"]
|
@include-section["find.scrbl"]
|
||||||
@include-section["future.scrbl"]
|
@include-section["future.scrbl"]
|
||||||
|
|
|
@ -19,7 +19,6 @@
|
||||||
(check-docs (quote unstable/function))
|
(check-docs (quote unstable/function))
|
||||||
(check-docs (quote unstable/find))
|
(check-docs (quote unstable/find))
|
||||||
(check-docs (quote unstable/file))
|
(check-docs (quote unstable/file))
|
||||||
(check-docs (quote unstable/exn))
|
|
||||||
(check-docs (quote unstable/debug))
|
(check-docs (quote unstable/debug))
|
||||||
(check-docs (quote unstable/contract))
|
(check-docs (quote unstable/contract))
|
||||||
(check-docs (quote unstable/class-iop))
|
(check-docs (quote unstable/class-iop))
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
#lang racket/base
|
#lang racket/base
|
||||||
(require unstable/bytes
|
(require unstable/bytes
|
||||||
unstable/contract
|
unstable/contract
|
||||||
unstable/exn
|
|
||||||
unstable/list
|
unstable/list
|
||||||
unstable/path
|
unstable/path
|
||||||
unstable/string
|
unstable/string
|
||||||
|
@ -10,8 +9,28 @@
|
||||||
(all-from-out
|
(all-from-out
|
||||||
unstable/bytes
|
unstable/bytes
|
||||||
unstable/contract
|
unstable/contract
|
||||||
unstable/exn
|
|
||||||
unstable/list
|
unstable/list
|
||||||
unstable/path
|
unstable/path
|
||||||
unstable/string
|
unstable/string
|
||||||
unstable/net/url))
|
unstable/net/url))
|
||||||
|
|
||||||
|
(require racket/contract/base
|
||||||
|
(for-syntax racket/base))
|
||||||
|
|
||||||
|
;; network-error: symbol string . values -> void
|
||||||
|
;; throws a formatted exn:fail:network
|
||||||
|
(define (network-error src fmt . args)
|
||||||
|
(raise (make-exn:fail:network (format "~a: ~a" src (apply format fmt args))
|
||||||
|
(current-continuation-marks))))
|
||||||
|
|
||||||
|
;; exn->string : (or/c exn any) -> string
|
||||||
|
(define (exn->string exn)
|
||||||
|
(if (exn? exn)
|
||||||
|
(parameterize ([current-error-port (open-output-string)])
|
||||||
|
((error-display-handler) (exn-message exn) exn)
|
||||||
|
(get-output-string (current-error-port)))
|
||||||
|
(format "~s\n" exn)))
|
||||||
|
|
||||||
|
(provide/contract
|
||||||
|
[network-error (->* [symbol? string?] [] #:rest list? void?)]
|
||||||
|
[exn->string (-> any/c string?)])
|
||||||
|
|
Loading…
Reference in New Issue
Block a user