Added unstable/cce/exn to unstable/exn.

This commit is contained in:
Carl Eastlund 2010-05-29 20:41:14 -04:00
parent 402232237c
commit 1360d02728
8 changed files with 49 additions and 67 deletions

View 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))))))

View File

@ -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)

View File

@ -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))
]
}

View File

@ -21,8 +21,6 @@
@include-section["require-provide.scrbl"]
@include-section["planet.scrbl"]
@include-section["exn.scrbl"]
@include-section["debug.scrbl"]
@include-section["scribble.scrbl"]

View File

@ -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))))))

View File

@ -5,7 +5,6 @@
"test-debug.ss"
"test-define.ss"
"test-dict.ss"
"test-exn.ss"
"test-planet.ss"
"test-require-provide.ss"
"test-scribble.ss"
@ -18,7 +17,6 @@
debug-suite
define-suite
dict-suite
exn-suite
planet-suite
require-provide-suite
scribble-suite

View File

@ -1,5 +1,6 @@
#lang racket/base
(require mzlib/contract)
(require racket/contract
(for-syntax racket/base))
;; network-error: symbol string . values -> void
;; throws a formatted exn:fail:network
@ -16,6 +17,16 @@
(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?) (listof any/c) . ->* . (void))]
[exn->string ((or/c exn? any/c) . -> . string?)])
[network-error (->* [symbol? string?] [] #:rest list? void?)]
[exn->string (-> any/c string?)])

View File

@ -1,6 +1,5 @@
#lang scribble/doc
@(require scribble/base
scribble/manual
#lang scribble/manual
@(require scribble/eval
"utils.rkt"
(for-label unstable/exn
racket/contract
@ -23,3 +22,24 @@
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))
]
}