Alice Project

The Exn structure

________ Synopsis ____________________________________________________

    signature EXN
    structure Exn : EXN

The structure Exn provides first-class access to raised exceptions, which allows controlling the generation of exception backtraces for debugging purposes.

See also: General

________ Import ______________________________________________________

Imported implicitly.

________ Interface ___________________________________________________

    signature EXN =
	exttype exn
	type t = exn
	type packet

	val name :       exn -> string
	val message :    exn -> string

	val fromPacket : packet -> exn
	val update :     packet * exn -> packet

	val catch :      (packet -> 'a) -> (unit -> 'a) -> 'a
	val reraise :    packet -> 'a
	val dumpTrace :  packet -> unit

________ Description _________________________________________________

exttype exn
type t = exn

The type of exceptions. Equivalent to the toplevel exn type.

type packet

The type of raised exception packets. Along with the exception proper, a packet carries information about its origin and a trace of its propagation history.

name ex

Returns a name for the exception ex. Equivalent to General.exnName ex.

message ex

Returns a message corresponding to exception ex. Equivalent to General.exnMessage ex.

fromPacket p

Retrieves the exception contained in the packet p.

update (p, ex)

Constructs a new packet by replacing the exception in packet p by ex.

catch handler f

Applies f() and returns its result. If an exception is raised, handler is invoked with the respective packet and its result is returned. The following equivalence holds:

        catch ((fn match) o fromPacket) (fn () => exp)  =  exp handle match
reraise p

Re-raises the packet p, without dropping its backtrace. Semantically equivalent to raise fromPacket p, but a backtrace of the raised exception will, when caught with catch, include the history of p.

dumpTrace p

Writes the backtrace of packet p to some implementation-dependent output (e.g. stderr). This function is provided solely for debugging convenience, the format and the destination of the dump is left unspecified.

last modified 2007/Mar/30 17:10