From 1360d02728e1755972e77b421b995ba01e1c5fe2 Mon Sep 17 00:00:00 2001 From: Carl Eastlund Date: Sat, 29 May 2010 20:41:14 -0400 Subject: [PATCH] Added unstable/cce/exn to unstable/exn. --- collects/tests/unstable/exn.rkt | 12 ++++++++ collects/unstable/cce/exn.ss | 11 ------- collects/unstable/cce/reference/exn.scrbl | 31 -------------------- collects/unstable/cce/reference/manual.scrbl | 2 -- collects/unstable/cce/test/test-exn.ss | 15 ---------- collects/unstable/cce/test/test-main.ss | 2 -- collects/unstable/exn.rkt | 17 +++++++++-- collects/unstable/scribblings/exn.scrbl | 26 ++++++++++++++-- 8 files changed, 49 insertions(+), 67 deletions(-) create mode 100644 collects/tests/unstable/exn.rkt delete mode 100644 collects/unstable/cce/exn.ss delete mode 100644 collects/unstable/cce/reference/exn.scrbl delete mode 100644 collects/unstable/cce/test/test-exn.ss diff --git a/collects/tests/unstable/exn.rkt b/collects/tests/unstable/exn.rkt new file mode 100644 index 0000000000..b774d7ba86 --- /dev/null +++ b/collects/tests/unstable/exn.rkt @@ -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)))))) diff --git a/collects/unstable/cce/exn.ss b/collects/unstable/cce/exn.ss deleted file mode 100644 index 5340eeccfd..0000000000 --- a/collects/unstable/cce/exn.ss +++ /dev/null @@ -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) diff --git a/collects/unstable/cce/reference/exn.scrbl b/collects/unstable/cce/reference/exn.scrbl deleted file mode 100644 index 6515d5df35..0000000000 --- a/collects/unstable/cce/reference/exn.scrbl +++ /dev/null @@ -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)) -] - -} diff --git a/collects/unstable/cce/reference/manual.scrbl b/collects/unstable/cce/reference/manual.scrbl index 7a557ea075..d6707a6356 100644 --- a/collects/unstable/cce/reference/manual.scrbl +++ b/collects/unstable/cce/reference/manual.scrbl @@ -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"] diff --git a/collects/unstable/cce/test/test-exn.ss b/collects/unstable/cce/test/test-exn.ss deleted file mode 100644 index 40d2f473a8..0000000000 --- a/collects/unstable/cce/test/test-exn.ss +++ /dev/null @@ -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)))))) diff --git a/collects/unstable/cce/test/test-main.ss b/collects/unstable/cce/test/test-main.ss index 7df513a7c7..2ccefeb3d9 100644 --- a/collects/unstable/cce/test/test-main.ss +++ b/collects/unstable/cce/test/test-main.ss @@ -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 diff --git a/collects/unstable/exn.rkt b/collects/unstable/exn.rkt index 7d9cdf3cea..edac8bf6c8 100644 --- a/collects/unstable/exn.rkt +++ b/collects/unstable/exn.rkt @@ -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?)]) diff --git a/collects/unstable/scribblings/exn.scrbl b/collects/unstable/scribblings/exn.scrbl index 4a63d0f22e..d4a4335f20 100644 --- a/collects/unstable/scribblings/exn.scrbl +++ b/collects/unstable/scribblings/exn.scrbl @@ -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)) +] + +}