▼ |  | Unstable: May Change Without Warning

1 | Guidelines for Developing unstable Libraries
2 | Automata: Compiling State Machines
3 | Bytes
4 | Contracts
5 | Contracts for Macro Subexpressions
6 | Debugging
7 | Definitions
8 | Errors
9 | Futures
10 | Functions
11 | Hash Tables
12 | Interface-Oriented Programming for Classes
13 | Lazy Require
14 | Lists
15 | Logging
16 | Macro Testing
17 | Mark Parameters
18 | Match
19 | Open place expressions
20 | Option Contracts
21 | Parameter Groups
22 | Pretty-Printing
23 | Re-Contracting Identifiers
24 | Sandbox
25 | Sequences
26 | Strings
27 | Structs
28 | Struct Printing
29 | Syntax
30 | Temporal Contracts: Explicit Contract Monitors
31 | Unix Domain Sockets
32 | 2D Syntax

On this page:

error*
raise-syntax-error*
compose-error-message
compose-error-detail
exn: not-break?
error-display

6.1.1
top ← prev up next →

### 8`` Errors

Ryan Culpepper <ryanc@racket-lang.org>

This library is unstable; compatibility will not be maintained. See Unstable: May Change Without Warning for more information.

(require unstable/error) | package: base

> > procedure
> > (error* |  | name |  |  |  |
> > |  | message |  |  |  |
> > |  | field |  |  |  |
> > |  | value ... |  |  |  |
> > |  | ... |  |  |  |
> > | [ | #:continued continued-message]) |  | → |  | any
> name : symbol?
> message : string?
> | field |  | : |  |
> (let ([option/c (or/c 'value 'multi 'maybe)])
> (or/c string? (cons/c string? (listof option/c))))
> value : any/c
> continued-message : (or/c string? (listof string?)) = null

Raises an exception with a message composed according to the Racket error message convention. The raised exception is an instance of exn:fail.

The composed error message includes details consisting of the alternating field and value arguments. By default, value is formatted as if by display unless it is #f, in which case the detail line is omitted. The following options affect the formatting of the detail line:

- 'multi formats each element in the corresponding value, which must be a list, as a separate line; if 'maybe is also provided, then the detail line is omitted if the list is empty

- 'value formats the value using error-value->string-handler; the detail line is not omittable unless 'maybe or 'multi is also provided

Examples:
> > (error* 'mcbean "too many stars upon thars"
> '("given" value) 'star-bellied-sneetch
> '("stars" value) 3)
> mcbean: too many stars upon thars
> given: 'star-bellied-sneetch
> stars: 3
> > (error* 'hal "unable to open pod bay doors"
> #:continued "this mission is too important to let you jeopardize it"
> "threat" "David Bowman"
> "detection" "lip reading")
> hal: unable to open pod bay doors;
> this mission is too important to let you jeopardize it
> threat: David Bowman
> detection: lip reading
> > (error* 'car "missing car keys"
> '("searched" multi)
> (list "dresser" "desk" "kitchen table" "under sofa"
> "behind microwave" "in washing machine")
> "last seen"
> #f)
> car: missing car keys
> searched:
> dresser
> desk
> kitchen table
> under sofa
> behind microwave
> in washing machine

> > procedure
> > (raise-syntax-error* |  | message |  |  |  |
> > |  | expr |  |  |  |
> > |  | sub-expr |  |  |  |
> > |  | field |  |  |  |
> > |  | value ... |  |  |  |
> > |  | ... |  |  |  |
> > | [ | #:continued continued-message]) |  | → |  | any
> message : string?
> expr : (or/c syntax? #f)
> sub-expr : (or/c syntax? #f)
> | field |  | : |  |
> (let ([option/c (or/c 'value 'multi 'maybe)])
> (or/c string? (cons/c string? (listof option/c))))
> value : any/c
> continued-message : (or/c string? (listof string?)) = null

Like raise-syntax-error but with the formatting of error*. The raised exception is an instance of exn:fail:syntax. Like raise-syntax-error, the inclusion of expr and sub-expr in the details of the error message is controlled by the error-print-source-location paramter; if they included, they are included before the other details specified by field and value. Unlike raise-syntax-error, both expr and sub-expr are mandatory arguments.

> > procedure
> > (compose-error-message |  | name |  |  |  |
> > |  | message |  |  |  |
> > |  | field |  |  |  |
> > |  | value ... |  |  |  |
> > |  | ... |  |  |  |
> > | [ | #:continued continued-message]) |  | → |  | string?
> name : (or/c symbol? #f)
> message : string?
> | field |  | : |  |
> (let ([option/c (or/c 'value 'multi 'maybe)])
> (or/c string? (cons/c string? (listof option/c))))
> value : any/c
> continued-message : (or/c string? (listof string?)) = null

Like error*, but produces a string conforming to the Racket error message convention.

> procedure (compose-error-detail field options value) → string?
> field : string?
> options : (listof (or/c 'value 'multi 'maybe))
> value : any/c

Formats a single detail for an error message. The options behave as described in error*.

The resulting string begins with a newline unless it is empty, so it can be appended to the end of a base error message.

> > > The subsequent bindings were added by Jay McCarthy.

> procedure (exn:not-break? x) → boolean?
> x : any/c

Identifies values that are not exn:break?, i.e. values that are safe to catch with with-handlers.

> procedure (error-display x) → void?
> x : any/c

Calls (error-display-handler) with the proper arguments whehter x is an exception, or not.
top ← prev up next →