From 4779dfad5f396024825346ad6007942fb8cfde62 Mon Sep 17 00:00:00 2001 From: Stuart Halloway Date: Fri, 28 Jan 2011 15:12:26 -0500 Subject: [PATCH] #733 data conveying exception --- src/clj/clojure/core_print.clj | 3 + src/jvm/clojure/lang/DataConveyingException.java | 92 ++++++++++++++++++++++ 2 files changed, 95 insertions(+), 0 deletions(-) create mode 100644 src/jvm/clojure/lang/DataConveyingException.java diff --git a/src/clj/clojure/core_print.clj b/src/clj/clojure/core_print.clj index a3c2e14..449f7b3 100644 --- a/src/clj/clojure/core_print.clj +++ b/src/clj/clojure/core_print.clj @@ -329,4 +329,7 @@ (and (instance? clojure.lang.IPromiseImpl o) (not (.hasValue o))) :not-delivered :else @o)), w)) +(defmethod print-method clojure.lang.DataConveyingException [o ^java.io.Writer w] + ((var print-defrecord) o w)) + (def ^{:private true} print-initialized true) diff --git a/src/jvm/clojure/lang/DataConveyingException.java b/src/jvm/clojure/lang/DataConveyingException.java new file mode 100644 index 0000000..f12df8e --- /dev/null +++ b/src/jvm/clojure/lang/DataConveyingException.java @@ -0,0 +1,92 @@ +/** + * Copyright (c) Rich Hickey. All rights reserved. + * The use and distribution terms for this software are covered by the + * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) + * which can be found in the file epl-v10.html at the root of this distribution. + * By using this software in any fashion, you are agreeing to be bound by + * the terms of this license. + * You must not remove this notice, or any other, from this software. + */ + +package clojure.lang; + +import java.util.Collection; +import java.util.Map; +import java.util.Set; + +public class DataConveyingException extends RuntimeException implements Map{ + // this will be immutable + public final Map data; + + private Map addStandardKeys(IPersistentMap data) { + return (Map) data.assoc(Keyword.intern("cause"), this.getCause()) + .assoc(Keyword.intern("message"), this.getMessage()); + } + + public DataConveyingException(IPersistentMap data) { + this.data = addStandardKeys(data); + } + + public DataConveyingException(IPersistentMap data, String s) { + super(s); + this.data = addStandardKeys(data); + } + + public DataConveyingException(IPersistentMap data, String s, Throwable throwable) { + super(s, throwable); + this.data = addStandardKeys(data); + } + + public DataConveyingException(IPersistentMap data, Throwable throwable) { + super(throwable); + this.data = addStandardKeys(data); + } + + public int size() { + return data.size(); + } + + public boolean isEmpty() { + return data.isEmpty(); + } + + public boolean containsKey(Object o) { + return data.containsKey(o); + } + + public boolean containsValue(Object o) { + return data.containsValue(o); + } + + public Object get(Object o) { + return data.get(o); + } + + public Object put(Object o, Object o1) { + return data.put(o, o1); + } + + public Object remove(Object o) { + throw new UnsupportedOperationException(); + } + + public void putAll(Map map) { + throw new UnsupportedOperationException(); + } + + public void clear() { + throw new UnsupportedOperationException(); + } + + public Set keySet() { + return data.keySet(); + } + + public Collection values() { + return data.values(); + } + + public Set entrySet() { + return data.entrySet(); + } +} -- 1.7.1