From 4b2c9cfbcc0fbff2c743202112137628ca202cc1 Mon Sep 17 00:00:00 2001 From: Tony Garnock-Jones Date: Mon, 8 Jun 2015 10:30:13 -0400 Subject: [PATCH] Add exn->string, following the function of the same name in the web-server. --- pkgs/racket-doc/scribblings/reference/exns.scrbl | 12 ++++++++++++ racket/collects/racket/exn.rkt | 10 ++++++++++ 2 files changed, 22 insertions(+) create mode 100644 racket/collects/racket/exn.rkt diff --git a/pkgs/racket-doc/scribblings/reference/exns.scrbl b/pkgs/racket-doc/scribblings/reference/exns.scrbl index 209f1b1095..ea26cdbddc 100644 --- a/pkgs/racket-doc/scribblings/reference/exns.scrbl +++ b/pkgs/racket-doc/scribblings/reference/exns.scrbl @@ -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)].} diff --git a/racket/collects/racket/exn.rkt b/racket/collects/racket/exn.rkt new file mode 100644 index 0000000000..7d8bc88df8 --- /dev/null +++ b/racket/collects/racket/exn.rkt @@ -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)))