sigildocs

(sigil exceptions)

(sigil exceptions) - Exception Handling (DEPRECATED)

This module is deprecated. Use (sigil error) instead. This module re-exports all symbols from (sigil error) for backward compatibility.

Exports

Create an exception with the given kind, message, and irritants.

Re-exported from (sigil core)

Create an exception with stack trace.

Re-exported from (sigil core)

exception?procedure

Check if obj is an exception.

Re-exported from (sigil core)

Get the kind of an exception (e.g., 'error, 'type-error).

Re-exported from (sigil core)

Get the message from an exception.

Re-exported from (sigil core)

Get the irritants (additional data) from an exception.

Re-exported from (sigil core)

Get the stack trace from an exception.

Re-exported from (sigil core)

raiseprocedure

Raise an exception (non-continuable). Aborts to the nearest exception handler.

Re-exported from (sigil core)

Raise a continuable exception. The handler can return a value to continue execution.

Re-exported from (sigil core)

errorprocedure

Convenience function to raise an error exception. (error "message" irritant ...)

Re-exported from (sigil core)

Install an exception handler and execute thunk (R6RS style). Handler is a procedure taking the exception. Thunk is the body to execute.

Re-exported from (sigil core)

Get the current exception handler.

Re-exported from (sigil core)

make-errorprocedure

Create a generic error exception.

(raise (make-error "Something went wrong"))
(raise (make-error "Invalid input" input-value))

Re-exported from (sigil error)

error?procedure

Test if an exception is a generic error.

(guard (exn
         ((error? exn) "generic error")
         (else "other"))
  (raise (make-error "oops")))
; => "generic error"

Re-exported from (sigil error)

Create a type error exception.

Use when a value has the wrong type.

(raise (make-type-error "Expected a number" 'number "hello"))

Re-exported from (sigil error)

type-error?procedure

Test if an exception is a type error.

(guard (exn
         ((type-error? exn) "type mismatch")
         (else "other"))
  (check-type x))

Re-exported from (sigil error)

Create a range error exception.

Use when a value is outside allowed bounds.

(raise (make-range-error "Index out of bounds" 10 0 5))

Re-exported from (sigil error)

range-error?procedure

Test if an exception is a range error.

(guard (exn
         ((range-error? exn) "out of bounds")
         (else "other"))
  (vector-ref v 100))

Re-exported from (sigil error)

Create an arity error exception.

Use when a function receives wrong number of arguments.

(raise (make-arity-error "Wrong number of arguments" 2 5))

Re-exported from (sigil error)

arity-error?procedure

Test if an exception is an arity error.

(guard (exn
         ((arity-error? exn) "wrong arg count")
         (else "other"))
  (apply my-func wrong-args))

Re-exported from (sigil error)

guardsyntax

Re-exported from (sigil error)

Format an exception as a human-readable string.

Includes the error kind, message, irritants, and stack trace.

(guard (exn
         (else (display (format-exception exn))))
  (error "something failed"))
; Error (error): something failed
;
; Stack trace (most recent call first):
;   0: my-function
;      at main.sgl:42:5

Re-exported from (sigil error)

Format a stack trace as a string.

By default, only shows frames with named functions, hiding anonymous lambdas to reduce noise from macro expansion and internal implementation. Pass #t to show all frames including anonymous ones.

(format-stack-trace (exception-stack-trace exn))
; =>   "0: my-function\n     at main.sgl:42:5\n  ..."

(format-stack-trace (exception-stack-trace exn) #t)  ; show all

Re-exported from (sigil error)