API for condition - clojure-contrib v1.2 (beta 1)

by Stephen C. Gilardi

Usage:
(ns your-namespace
  (:require clojure.contrib.condition))

Overview

Flexible raising and handling of conditions:

Functions:

              raise: raises a condition
       handler-case: dispatches raised conditions to appropriate handlers
  print-stack-trace: prints abbreviated or full condition stack traces

Data:

  A condition is a map containing values for these keys:

    - :type, a condition type specifier, typically a keyword
    - :stack-trace, a stack trace to the site of the raise
    - :message, a human-readable message (optional)
    - :cause, a wrapped exception or condition (optional)
    - other keys given as arguments to raise (optional)

Note: requires AOT compilation.

Based on an idea from Chouser:
http://groups.google.com/group/clojure/browse_frm/thread/da1285c538f22bb5

Public Variables and Functions



*full-stack-traces*

var

  
Bind to true to include clojure.{core,lang,main} frames in stack
traces
Source


handler-case

macro
Usage: (handler-case dispatch-fn & body)
Executes body in a context where raised conditions can be handled.

dispatch-fn accepts a raised condition (a map) and returns a selector
used to choose a handler. Commonly, dispatch-fn will be :type to dispatch
on the condition's :type value.

Handlers are forms within body:

  (handle key
    ...)

If a condition is raised, executes the body of the first handler whose
key satisfies (isa? selector key). If no handlers match, re-raises the
condition.

While a handler is running, *condition* is bound to the condition being
handled and *selector* is bound to to the value returned by dispatch-fn
that matched the handler's key.
Source


print-stack-trace

function
Usage: (print-stack-trace x)
Prints a stack trace for a condition or Throwable. Skips frames for
classes in clojure.{core,lang,main} unless the *full-stack-traces* is
bound to logical true
Source


raise

macro
Usage: (raise)
       (raise m)
       (raise key val & keyvals)
Raises a condition. With no arguments, re-raises the current condition.
With one argument (a map), raises the argument. With two or more
arguments, raises a map with keys and values from the arguments.
Source


stack-trace-info

multimethod
No usage documentation available
Returns header, stack-trace, and cause info from conditions and
Throwables
Source

condition.Condition






-init

function
Usage: (-init condition)
Constructs a Condition object with condition (a map) as its
metadata. Also initializes the superclass with the values at :message
and :cause, if any, so they are also available via .getMessage and
.getCause.
Source

-meta

function
Usage: (-meta this)
Returns this object's metadata, the condition
Source

-post-init

function
Usage: (-post-init this condition)
Adds :stack-trace to the condition. Drops the bottom 3 frames because
they are always the same: implementation details of Condition and raise.
Source
Logo & site design by Tom Hickey.
Clojure auto-documentation system by Tom Faulhaber.