The following is a basic error handling package that enables you to trap errors in Qi and redirect them in a type secure way. It depends on some functions in CL, however no grasp of CL is needed to understand them. There are only two functions in this package. trap-error X : A; F : (error --> A); This function takes an expression X of type A and evaluates it. If no error is returned, then the normal form of X is returned. If an error is raised then the error condition is passed to its second argument which returns an expression of type A. Note this expression is coded as a transparent CL macro and cannot be curried; it has its own type rule. error-to-string : error --> string This function takes an error condition and turns it into a string. Examples: (trap-error (/ 1 0)
(/. E -1)) (trap-error (/ 1 0)
(/. E (do (output (error-to-string E)) -1))) (trap-error (/ 1 0)
(/. E (let S (error-to-string E)(if (= S "too
large") 1 -1)))) Mark Copyright (c) 2008, Mark
Tarver |
||