Problem: When I connect to a socket server and create a thread, exceptions 
in the thread are printed in the server's process, not the client's. I'd 
like them to appear in the client's process, where the thread was created.

(I'm using the term "process" very generally here, because I don't 
understand what is going on.)

>From searching, I understand that there are some other things at play, like 
System/err, but I don't understand what is happening or how I can work 
around it. Why does an exception thrown in the client process show in the 
client process, but an exception thrown in a thread created by the client 
process shows in the server process? Why doesn't binding *err* in a thread 
seem to have any effect? Any suggestions or workarounds?

I'm not using futures, because this is a long-running process that never 
returns a value.

Example transcript:

# Socker server

(The only command entered is the first one, which begins with clj. 
Everything after "user=>" is due to the client below.)

$ clj -J-Dclojure.server.myrepl='{:port 
5555,:accept,clojure.core.server/repl}'
Clojure 1.10.1
user=> My second message.
Exception in thread "Thread-0" clojure.lang.ExceptionInfo: My second 
exception {}
    at user$eval5$fn__141.invoke(NO_SOURCE_FILE:7)
    at clojure.lang.AFn.run(AFn.java:22)
    at java.lang.Thread.run(Thread.java:745)
Exception in thread "Thread-1" clojure.lang.ExceptionInfo: My third 
exception {}
    at user$eval144$fn__145.invoke(NO_SOURCE_FILE:16)
    at clojure.lang.AFn.run(AFn.java:22)
at java.lang.Thread.run(Thread.java:745)

# Client

$ nc localhost 5555
user=> (println "My first message.")
My first message.
nil
user=> (throw (ex-info "My first exception." {}))
Execution error (ExceptionInfo) at user/eval3 (REPL:2).
My first exception.
user=> (.start
 (Thread.
  (fn []
    (println "My second message.")
    (throw (ex-info "My second exception" {})))))
nil
user=> (.start
 (Thread.
  (let [out *out*
        err *err*]
    (fn []
      (binding [*out* out
                *err* err]
        (println "My third message.")
        (throw (ex-info "My third exception" {})))))))
nil
My third message.

Any clues would be appreciated. Thanks!

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/clojure/d084b0c0-0a1b-4db2-95a1-f38ff894bfa6n%40googlegroups.com.

Reply via email to