On this page:
error*
raise-syntax-error*
compose-error-message
compose-error-detail
exn:  not-break?
error-display
7.1

7 Errors

Ryan Culpepper <[email protected]>

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

 (require unstable/error) package: unstable-lib

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:

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 whether x is an exception, or not.