@@ -50,20 +50,26 @@ Binary data is represented using the protocol BinaryData; this protocol is exten
5050BinaryData is simply a randomly accessible collection of bytes, with a known length.
5151
5252``` clojure
53- (println ( format -binary " Choose immutability and see where it takes you." ) )
53+ (write -binary " Choose immutability and see where it takes you." )
5454```
5555
5656```
57570000: 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
58580020: 65 20 69 74 20 74 61 6B 65 73 20 79 6F 75 2E
5959```
6060
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)
6262
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 )
6468
6569If the two data are of different lengths, the shorter one is padded with ` -- ` to make up the difference.
6670
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+
6773## io.aviso.exception
6874
6975Exceptions in Clojure are extremely painful for many reasons:
@@ -74,9 +80,53 @@ Exceptions in Clojure are extremely painful for many reasons:
7480* Stack traces are often truncated, obscuring vital information
7581* Many stack frames represent implementation details of Clojure that are not relevant
7682
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 ` :
78126
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
80130any property that returns a non-nil Throwable type, not just the rootCause property; this makes it properly expand older exceptions
81131that do not set the rootCause property.
82132
@@ -85,4 +135,5 @@ It displays the class name of each exception, its message, and any non-nil prope
85135The all-important stack trace is carefully formatted for readability, with the left-most column identifying Clojure functions, the middle columns
86136presenting the file name and line number, and the right-most columns the Java class and method names.
87137
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