XLISP errset

Nyquist / XLISP 2.0 - Contents | Tutorials | Examples | Reference

# errset

Type: | - | special form (fsubr)
Source: | - | xlcont.c

## Syntax

(errset expr [print-flag])
  expr - an expression to be evaluated
  print-flag - an optional expression [NIL or non-NIL]
  returns - the value of the last expression consed with NIL , or NIL on error

## Description

The 'errset' special form is a mechanism that allows the trapping of errors within the execution of 'expr'. *breakenable* must be set to NIL for the 'errset' form to function. If *breakenable* is non-NIL , the normal break loop will handle the error. For 'errset', if no error occurs within 'expr', the value of the last expression is consed with NIL. If an error occurs within 'expr', the error is caught by 'errset' and a NIL is returned from 'errset'. If 'print-flag' is NIL , the error message normally generated by 'expr' will not be printed. If 'print-flag' is non-NIL or not present in the 'errset' form, the error message will be printed.

Errors from error and cerror and system errors will be handled by 'errset'. Note that the cerror message will only include the error message portion, not the continue message portion. break is not intercepted by 'errset'.

## Examples

    (setq *breakenable* nil)          ; do not enter the break-loop on errors
    (errset (error "hi" "ho"))        ; prints  error: hi - "ho" returns NIL
    (errset (cerror "hi" "ho" "he"))  ; prints  error: ho - "he" returns NIL
    (errset (error "hey" "ho") NIL)   ; returns NIL
    (errset (break "hey"))            ; break: hey - if continued: return from BREAK
    (continue)                        ; [ continue from break loop ]
    (errset (+ 1 5))                  ; returns (6)
    (errset (+ 1 "a") NIL)            ; returns NIL
    (setq *breakenable* t)            ; re-enable the break-loop on errors

How to keep XLISP from signalling an error:

    (setq *breakenable* nil)
    (errset expression-causing-an-error t)  ; print the error message
    (errset expression-causing-an-error)    ; do NOT print the error message

Note: Be sure to set *breakenable* to NIL before using 'errset' and to non-NIL after using 'errset'. If you don't reset *breakenable* , no errors will be reported.

See the errset function in the XLISP 2.0 manual.

Back to Top

Nyquist / XLISP 2.0 - Contents | Tutorials | Examples | Reference