Add exn->string, following the function of the same name in the web-server.

This commit is contained in:
Tony Garnock-Jones 2015-06-08 10:30:13 -04:00 committed by Matthew Flatt
parent 502575b641
commit 4b2c9cfbcc
2 changed files with 22 additions and 0 deletions

View File

@ -960,3 +960,15 @@ property, @racket[#f] otherwise.}
(exn:missing-module? . -> . module-path?)]{
Returns the @tech{module path}-getting procedure associated with @racket[v].}
@;------------------------------------------------------------------------
@section{Additional Exception Functions}
@note-lib-only[racket/exn]
@defproc[(exn->string [exn (or/c exn? any/c)]) string?]{
Formats @racket[exn] as a string. If @racket[exn] is an @racket[exn?],
collects and returns the output from the current
@racket[(error-display-handler)]; otherwise, simply converts
@racket[exn] to a string using @racket[(format "~s\n" exn)].}

View File

@ -0,0 +1,10 @@
#lang racket/base
(provide exn->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)))