The Problem
I want deeply detailed information about exceptions, as a generic facility. The information should be useful for programmatic and human consumption.
Assumptions / Constraints
- Integrate well with platform
- Work ok for interop callers
- Exceptions are not for flow control
Phase One
Provide built-in Clojure exception types that are richer than Java exceptions, and eliminate the need for app developers to gen-class their own exception types. Since some information is costly to provide, provide a *debug* flag that allows the costly stuff to be disabled in production.
Debug Builds
- the following group of features will be enabled when
*debug*is set- assert
*unchecked-math*math becomes checked math- explicit unchecked does not change (might be for semantic reasons)
- include locals (and bindings ??) in all thrown errors (or in assertions if this is too hard)
- is conditional in
throwpath too expensive? - otherwise compile
throwdifferently based on flag
- is conditional in
- unify with Java assertions?
- Not now. this can be done as a separate enhancement later
- see discussion at http://dev.clojure.org/jira/browse/CLJ-250
- Need separate assert-like constructs that never get turned off
- typical name:
verify - for preconditions: prefix either
verify-orassert-to:preand:post??- what is the default ??
- typical name:
Errors as Data
Provide built-in types than extend Throwable and implement IPersistentMap. Goal: The new types are capable enough that Clojure programmers can be out of the business of making new Throwable subclasses.
- expose error info as part of the map
- clojure owns unnamespaced keywords
- include :namespace key
- will be a great match target, alleviate one want for typed exceptions
- no need to include :fn key
- not a good match target
- available for human consumption in context of stacktrace
- need a few different types
- error, runtimeexception, assertion?
- need names
- unworkable: Clojure, PersistentMap,
- maybe: Condition (but don't want to suggest non-error flow control)
- provide fn that parses Java exceptions into similar maps
- e.g. clj-stacktrace
- REPL exception help works in terms of maps, not Java exceptions