Phase Next
These are much less well considered! The primary reason for documenting them now is merely to make sure that nothing in Phase One blocks future development.
What's the Problem?
- Exception throwers have the details and the context, and high level handlers have the policy. The right information is all available, but not all at the same time and place:
- Throwers have to anticipate what handlers might need.
- Handlers miss the time window to recover from the problem as it happens--the stack is already unwound.
- Programmatic response to errors based on types is inflexible
- Inheritance hierarchy baked in
- Have to manufacture new types to drive dispatch
Condition System
- adopt matchure as general purpose matching strategy
- update implementation to use protocols instead of multimethods
- matching will work with class of plain Java exceptions
- and also work with maplikeness of Clojure exceptions
- How to prevent people from writing handlers that rely on debug-build information?
- yes: warn users through documentation
- no: parse matching forms and reject
- no: give locals and bindings ugly "debug" names
- possible approach
- extend try/catch/finally with
handle
handle
takes two args: error and context- match on error to grab exceptions unwinding
- then walk stack of registered handlers, matching on context
- note that context is arbitrary object
- it could be, or include, the error!
- handler is fn of two args (error, context)
- if not a fn, could be literal value for simple case
- tools would be able to allow interactive restart, a la CL
- note that this approach puts more responsibility on
top
and less onmiddle
(when compared to CL)
- extend try/catch/finally with
Better Java Unification
ISnapshot
protocol identifies Java objects that can be "immutable data-ized"- protocol extends to throwable
- other possible cool uses
- dynamic codegen of nonreflective code a la
clojure.core/bean
- dynamic codegen of nonreflective code a la
- extend condition system to call through
ISnapshot
where available- get power of matching with plain ol' Java exceptions!
- simplify REPL and reporting code
- all exceptions can now be treated as data, from Java or from Clojure
- would snaphsot need to be memoized ??
- probably
- simple LRU might be good enough
- or could use a weak map keyed by base object
- do exceptions consume any native resources?
- if unification with Java was good enough, could we drop the Clojure-specific exceptions?
- unlikely – bottom needs to be separable
- if
IMeta
orIPersistentMap
were protocols...
Labels:
2 Comments
Hide/Show CommentsJan 04, 2011
Rich Hickey
No clue as to what problems this solves
Jan 13, 2011
Stuart Halloway
Lots of folks want conditions. I don't want them (yet) -- this page is just brainstorming to identify constraints a future condition system might put on what we are doing now. Short answer: didn't find any.