Raising Conditions

You can raise conditions in user-code.

You can raise standard Idio errors with error for a generic ^idio-error or error/type for a more specific condition type.

You can raise a specific condition with raise which supports any kind of condition type, including user-defined ones.

Finally, reraise supports a niche problem where you recognise that, as a handler potentially several layers down in the trap-handling stack, you are raising a new condition for which the user might have defined a handler some layers above where you are now. What reraise does is look for the highest numbered trap-handler on the stack and start (again) with it.

function error loc msg [detail]

raise an ^idio-error

Param loc:

function name

Type loc:

symbol

Param msg:

error message

Type loc:

string

Param detail:

detailed arguments, defaults to #n

Type detail:

list, optional

This does not return!

function error/type ct loc msg [detail [...]]

raise a ct condition

Param ct:

condition type

Type ct:

condition type

Param loc:

function name

Type loc:

symbol

Param msg:

error message

Type loc:

string

Param detail:

detailed arguments, defaults to #n

Type detail:

list, optional

This does not return!

Example:

Suppose you want to validate what should be a string argument for a minimum length:

define (frob-string str) {
  (or (string? s)
      (error/type ^rt-parameter-type-error 'frob-string "not a string" s))
  (or ((string-length s) gt 10)
      (error/type ^rt-parameter-value-error 'frob-string "string should be > 10 code points" s))
  ...
}

frob-string #t       ; ^rt-parameter-type-error:not a string (#t) at frob-string: detail (#t)
frob-string "hello"  ; ^rt-parameter-value-error:string should be > 10 code points ("hello") at frob-string: detail ("hello")
function raise c

raise the condition c

!! MAY RETURN !!

Param c:

condition to raise

Type c:

condition

Return:

#<unspec>

function reraise c

reraise the condition c

In particular this rediscovers the top-most trap handler.

Param c:

condition to raise

Type c:

condition

Last built at 2024-05-17T06:10:45Z+0000 from 62cca4c (dev) for Idio 0.3.b.6