Added unstable/cce/exn to unstable/exn.
This commit is contained in:
parent
402232237c
commit
1360d02728
12
collects/tests/unstable/exn.rkt
Normal file
12
collects/tests/unstable/exn.rkt
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
#lang racket
|
||||||
|
|
||||||
|
(require rackunit rackunit/text-ui unstable/exn "helpers.rkt")
|
||||||
|
|
||||||
|
(run-tests
|
||||||
|
(test-suite "exn.ss"
|
||||||
|
(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,11 +0,0 @@
|
||||||
#lang scheme
|
|
||||||
|
|
||||||
(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)
|
|
|
@ -1,31 +0,0 @@
|
||||||
#lang scribble/doc
|
|
||||||
@(require scribble/manual
|
|
||||||
scribble/eval
|
|
||||||
"../scribble.ss"
|
|
||||||
"eval.ss")
|
|
||||||
@(require (for-label scheme unstable/cce/exn))
|
|
||||||
|
|
||||||
@title[#:style 'quiet #:tag "cce-exn"]{Exceptions}
|
|
||||||
|
|
||||||
@defmodule[unstable/cce/exn]
|
|
||||||
|
|
||||||
This module provides tools for dealing with exceptions.
|
|
||||||
|
|
||||||
@defform[(try expr ...+)]{
|
|
||||||
|
|
||||||
Executes the first expression @scheme[expr] in the sequence, producing its
|
|
||||||
result value(s) if it returns any. If it raises an exception instead,
|
|
||||||
@scheme[try] continues with the next @scheme[expr]. Exceptions raised by
|
|
||||||
intermediate expressions are reported to the @tech[#:doc '(lib
|
|
||||||
"scribblings/reference/reference.scrbl")]{current logger} at the @scheme['debug]
|
|
||||||
level before continuing. Exceptions raised by the final expression are not
|
|
||||||
caught by @scheme[try].
|
|
||||||
|
|
||||||
@defexamples[
|
|
||||||
#:eval (evaluator 'unstable/cce/exn)
|
|
||||||
(try (+ 1 2) (+ 3 4))
|
|
||||||
(try (+ 'one 'two) (+ 3 4))
|
|
||||||
(try (+ 'one 'two) (+ 'three 'four))
|
|
||||||
]
|
|
||||||
|
|
||||||
}
|
|
|
@ -21,8 +21,6 @@
|
||||||
@include-section["require-provide.scrbl"]
|
@include-section["require-provide.scrbl"]
|
||||||
@include-section["planet.scrbl"]
|
@include-section["planet.scrbl"]
|
||||||
|
|
||||||
@include-section["exn.scrbl"]
|
|
||||||
|
|
||||||
@include-section["debug.scrbl"]
|
@include-section["debug.scrbl"]
|
||||||
|
|
||||||
@include-section["scribble.scrbl"]
|
@include-section["scribble.scrbl"]
|
||||||
|
|
|
@ -1,15 +0,0 @@
|
||||||
#lang scheme
|
|
||||||
|
|
||||||
(require "checks.ss"
|
|
||||||
"../exn.ss")
|
|
||||||
|
|
||||||
(provide exn-suite)
|
|
||||||
|
|
||||||
(define exn-suite
|
|
||||||
(test-suite "exn.ss"
|
|
||||||
(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))))))
|
|
|
@ -5,7 +5,6 @@
|
||||||
"test-debug.ss"
|
"test-debug.ss"
|
||||||
"test-define.ss"
|
"test-define.ss"
|
||||||
"test-dict.ss"
|
"test-dict.ss"
|
||||||
"test-exn.ss"
|
|
||||||
"test-planet.ss"
|
"test-planet.ss"
|
||||||
"test-require-provide.ss"
|
"test-require-provide.ss"
|
||||||
"test-scribble.ss"
|
"test-scribble.ss"
|
||||||
|
@ -18,7 +17,6 @@
|
||||||
debug-suite
|
debug-suite
|
||||||
define-suite
|
define-suite
|
||||||
dict-suite
|
dict-suite
|
||||||
exn-suite
|
|
||||||
planet-suite
|
planet-suite
|
||||||
require-provide-suite
|
require-provide-suite
|
||||||
scribble-suite
|
scribble-suite
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
#lang racket/base
|
#lang racket/base
|
||||||
(require mzlib/contract)
|
(require racket/contract
|
||||||
|
(for-syntax racket/base))
|
||||||
|
|
||||||
;; network-error: symbol string . values -> void
|
;; network-error: symbol string . values -> void
|
||||||
;; throws a formatted exn:fail:network
|
;; throws a formatted exn:fail:network
|
||||||
|
@ -16,6 +17,16 @@
|
||||||
(format "~s\n" exn)))
|
(format "~s\n" exn)))
|
||||||
;; Eli: (or/c exn any)??
|
;; 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
|
(provide/contract
|
||||||
[network-error ((symbol? string?) (listof any/c) . ->* . (void))]
|
[network-error (->* [symbol? string?] [] #:rest list? void?)]
|
||||||
[exn->string ((or/c exn? any/c) . -> . string?)])
|
[exn->string (-> any/c string?)])
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
#lang scribble/doc
|
#lang scribble/manual
|
||||||
@(require scribble/base
|
@(require scribble/eval
|
||||||
scribble/manual
|
|
||||||
"utils.rkt"
|
"utils.rkt"
|
||||||
(for-label unstable/exn
|
(for-label unstable/exn
|
||||||
racket/contract
|
racket/contract
|
||||||
|
@ -23,3 +22,24 @@
|
||||||
string?]{
|
string?]{
|
||||||
Formats @racket[exn] with @racket[(error-display-handler)] as a 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 @scheme[expr] in the sequence, producing its
|
||||||
|
result value(s) if it returns any. If it raises an exception instead,
|
||||||
|
@scheme[try] continues with the next @scheme[expr]. Exceptions raised by
|
||||||
|
intermediate expressions are reported to the @tech[#:doc '(lib
|
||||||
|
"scribblings/reference/reference.scrbl")]{current logger} at the @scheme['debug]
|
||||||
|
level before continuing. Exceptions raised by the final expression are not
|
||||||
|
caught by @scheme[try].
|
||||||
|
|
||||||
|
@defexamples[
|
||||||
|
#:eval (eval/require 'unstable/exn)
|
||||||
|
(try (+ 1 2) (+ 3 4))
|
||||||
|
(try (+ 'one 'two) (+ 3 4))
|
||||||
|
(try (+ 'one 'two) (+ 'three 'four))
|
||||||
|
]
|
||||||
|
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user