@@ -50,20 +50,26 @@ Binary data is represented using the protocol BinaryData; this protocol is exten
50
50
BinaryData is simply a randomly accessible collection of bytes, with a known length.
51
51
52
52
``` clojure
53
- (println ( format -binary " Choose immutability and see where it takes you." ) )
53
+ (write -binary " Choose immutability and see where it takes you." )
54
54
```
55
55
56
56
```
57
57
0000: 43 68 6F 6F 73 65 20 69 6D 6D 75 74 61 62 69 6C 69 74 79 20 61 6E 64 20 73 65 65 20 77 68 65 72
58
58
0020: 65 20 69 74 20 74 61 6B 65 73 20 79 6F 75 2E
59
59
```
60
60
61
- You can also compare two binary data values:
61
+ ` write-binary ` can write to a ` java.io.Writer ` (defaulting to ` *out* ` ) or a ` StringBuilder ` (or other things, as defined by ` io.aviso.writer/Writer ` protocol)
62
62
63
- ![ ] ( https://www.evernote.com/shard/s54/sh/d7d3942b-d99f-4ab7-a572-04186495c49b/841bbc6d91db0a1927a4fbc67336569d/deep/0/REPL%20and%20binary.clj%20-%20%5Bpretty%5D%20-%20pretty%20-%20%5B~/workspaces/annadale/pretty%5D.png )
63
+ Alternately, ` format-binary ` will return this formatted binary output string.
64
+
65
+ You can also compare two binary data values with ` write-binary-delta ` :
66
+
67
+ ![ ] ( https://www.evernote.com/shard/s54/sh/dc407aa4-a81e-4851-abed-3ca2949efba1/dfa5d033da855b1a97dd899682ea01fd/deep/0/README.md%20-%20%5Bpretty%5D%20-%20pretty%20-%20%5B~/workspaces/annadale/pretty%5D%20and%20stages.clj%20-%20%5Bswitch%5D%20-%20nexus%20-%20%5B~/workspaces/annadale/nexus%5D.png )
64
68
65
69
If the two data are of different lengths, the shorter one is padded with ` -- ` to make up the difference.
66
70
71
+ As with ` write-binary ` , there's a ` format-binary-delta ` , and a three-argument version of ` write-binary-delta ` for specifying a Writer target.
72
+
67
73
## io.aviso.exception
68
74
69
75
Exceptions in Clojure are extremely painful for many reasons:
@@ -74,9 +80,53 @@ Exceptions in Clojure are extremely painful for many reasons:
74
80
* Stack traces are often truncated, obscuring vital information
75
81
* Many stack frames represent implementation details of Clojure that are not relevant
76
82
77
- This is addressed by the ` format-exception ` function, which takes an exception and converts it to a string, ready to be printed to the console.
83
+ This is addressed by the ` write-exception ` function; it take an exception formats it nearly to a Writer, again ` *out* ` by
84
+ \default.
85
+
86
+ This is best explained by example; here's a ` SQLException ` wrapped inside two ` RuntimeException ` s, and printed normally:
87
+
88
+ ```
89
+ (.printStackTrace e)
90
+ => nil
91
+ java.lang.RuntimeException: Request handling exception
92
+ at user$make_exception.invoke(user.clj:6)
93
+ at clojure.lang.AFn.applyToHelper(AFn.java:159)
94
+ at clojure.lang.AFn.applyTo(AFn.java:151)
95
+ at clojure.lang.Compiler$InvokeExpr.eval(Compiler.java:3458)
96
+ at clojure.lang.Compiler$DefExpr.eval(Compiler.java:408)
97
+ at clojure.lang.Compiler.eval(Compiler.java:6624)
98
+ at clojure.lang.Compiler.eval(Compiler.java:6582)
99
+ at clojure.core$eval.invoke(core.clj:2852)
100
+ at clojure.main$repl$read_eval_print__6588$fn__6591.invoke(main.clj:259)
101
+ at clojure.main$repl$read_eval_print__6588.invoke(main.clj:259)
102
+ at clojure.main$repl$fn__6597.invoke(main.clj:277)
103
+ at clojure.main$repl.doInvoke(main.clj:277)
104
+ at clojure.lang.RestFn.invoke(RestFn.java:1096)
105
+ at clojure.tools.nrepl.middleware.interruptible_eval$evaluate$fn__876.invoke(interruptible_eval.clj:56)
106
+ at clojure.lang.AFn.applyToHelper(AFn.java:159)
107
+ at clojure.lang.AFn.applyTo(AFn.java:151)
108
+ at clojure.core$apply.invoke(core.clj:617)
109
+ at clojure.core$with_bindings_STAR_.doInvoke(core.clj:1788)
110
+ at clojure.lang.RestFn.invoke(RestFn.java:425)
111
+ at clojure.tools.nrepl.middleware.interruptible_eval$evaluate.invoke(interruptible_eval.clj:41)
112
+ at clojure.tools.nrepl.middleware.interruptible_eval$interruptible_eval$fn__917$fn__920.invoke(interruptible_eval.clj:171)
113
+ at clojure.core$comp$fn__4154.invoke(core.clj:2330)
114
+ at clojure.tools.nrepl.middleware.interruptible_eval$run_next$fn__910.invoke(interruptible_eval.clj:138)
115
+ at clojure.lang.AFn.run(AFn.java:24)
116
+ at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
117
+ at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
118
+ at java.lang.Thread.run(Thread.java:680)
119
+ Caused by: java.lang.RuntimeException: Failure updating row
120
+ ... 27 more
121
+ Caused by: java.sql.SQLException: Database failure
122
+ ... 27 more
123
+ ```
124
+
125
+ ... and here's the equivalent, via ` write-exception ` :
78
126
79
- ` format-exception ` navigates down the exception hierarchy; it only presents the stack trace for the deepest, or root, exception. It can navigate
127
+ ![ ] ( https://www.evernote.com/shard/s54/sh/be166f69-ce90-4f27-af63-cf76511516e0/9a36d82f5bd67e220887901639529630/deep/0/Appendable.java%20-%20%5B1.6%5D%20-%20pretty%20-%20%5B~/workspaces/annadale/pretty%5D.png )
128
+
129
+ ` write-exception ` navigates down the exception hierarchy; it only presents the stack trace for the deepest, or root, exception. It can navigate
80
130
any property that returns a non-nil Throwable type, not just the rootCause property; this makes it properly expand older exceptions
81
131
that do not set the rootCause property.
82
132
@@ -85,4 +135,5 @@ It displays the class name of each exception, its message, and any non-nil prope
85
135
The all-important stack trace is carefully formatted for readability, with the left-most column identifying Clojure functions, the middle columns
86
136
presenting the file name and line number, and the right-most columns the Java class and method names.
87
137
88
- ![ ] ( https://www.evernote.com/shard/s54/sh/7df05675-3d07-463e-b27c-195214b2a854/2333cd1a62d550522f6a4534b129dd58/deep/0/REPL%20and%20binary.clj%20-%20%5Bpretty%5D%20-%20pretty%20-%20%5B~/workspaces/annadale/pretty%5D.png )
138
+ The related function, ` format-exception ` , produces the same output, but returns it as a string.
139
+
0 commit comments