This repository was archived by the owner on Apr 25, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 4 files changed +32
-5
lines changed
test/clojure/test_clojure Expand file tree Collapse file tree 4 files changed +32
-5
lines changed Original file line number Diff line number Diff line change 4287
4287
(with-out-str
4288
4288
(apply println xs)))
4289
4289
4290
- (import clojure.lang.ExceptionInfo)
4290
+ (import clojure.lang.ExceptionInfo clojure.lang.IExceptionInfo )
4291
4291
(defn ex-info
4292
4292
" Alpha - subject to change.
4293
4293
Create an instance of ExceptionInfo, a RuntimeException subclass
4300
4300
4301
4301
(defn ex-data
4302
4302
" Alpha - subject to change.
4303
- Returns exception data (a map) if ex is an ExceptionInfo .
4303
+ Returns exception data (a map) if ex is an IExceptionInfo .
4304
4304
Otherwise returns nil."
4305
4305
{:added " 1.4" }
4306
4306
[ex]
4307
- (when (instance? ExceptionInfo ex)
4308
- (.getData ^ExceptionInfo ex)))
4307
+ (when (instance? IExceptionInfo ex)
4308
+ (.getData ^IExceptionInfo ex)))
4309
4309
4310
4310
(defmacro assert
4311
4311
" Evaluates expr and throws an exception if it does not evaluate to
Original file line number Diff line number Diff line change 15
15
* richer semantics for exceptions should use this in lieu of defining project-specific
16
16
* exception classes.
17
17
*/
18
- public class ExceptionInfo extends RuntimeException {
18
+ public class ExceptionInfo extends RuntimeException implements IExceptionInfo {
19
19
public final IPersistentMap data ;
20
20
21
21
public ExceptionInfo (String s , IPersistentMap data ) {
Original file line number Diff line number Diff line change
1
+ /**
2
+ * Copyright (c) Rich Hickey. All rights reserved.
3
+ * The use and distribution terms for this software are covered by the
4
+ * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
5
+ * which can be found in the file epl-v10.html at the root of this distribution.
6
+ * By using this software in any fashion, you are agreeing to be bound by
7
+ * the terms of this license.
8
+ * You must not remove this notice, or any other, from this software.
9
+ */
10
+
11
+ package clojure .lang ;
12
+
13
+ /**
14
+ * Interface for exceptions that carry data (a map) as additional payload. Clojure
15
+ * programs that need richer semantics for exceptions should use this in lieu of
16
+ * defining project-specific exception classes.
17
+ */
18
+ public interface IExceptionInfo {
19
+ public IPersistentMap getData ();
20
+ }
Original file line number Diff line number Diff line change 45
45
(is (thrown-with-msg? IllegalArgumentException
46
46
(re-pattern (format msg-regex-str *ns*))
47
47
(macroexpand form)))))
48
+
49
+ (deftest extract-ex-data
50
+ (try
51
+ (throw (ex-info " example error" {:foo 1 }))
52
+ (catch Throwable t
53
+ (is (= {:foo 1 } (ex-data t)))))
54
+ (is (nil? (ex-data (RuntimeException. " example non ex-data" )))))
You can’t perform that action at this time.
0 commit comments