title: Attach jdb on uncaught exception
body: <p>So, I am starting a Java program as below </p>
  
  <pre><code>java -agentlib:jdwp=transport=dt_socket,address=8000, server=y,suspend=n  MyClass
  </code></pre>
  
  <p>I then manually attach a debugger as below</p>
  
  <pre><code>jdb -attach 8000
  </code></pre>
  
  <p>I would like to know if there is anyway for me to set up jdb so that it automatically attaches to the running process (only) in the case of an uncaught exception?</p>
  
  <p>The reason being that I would like to avoid the overhead of the debugger until an uncaught exception arises. But the problem I face now is that if the debugger is not attached, then the JVM aborts once an uncaught exception arises. </p>
  
  <p>EDIT:</p>
  
  <p>From the Oracle <a href="http://docs.oracle.com/javase/1.5.0/docs/guide/jpda/conninv.html#JDB" rel="nofollow">docs</a>, it seems the below command does what I need, but for windows machines.</p>
  
  <pre><code>java -agentlib:jdwp=transport=dt_shmem,server=y,onuncaught=y,launch=d:\bin\debugstub.exe MyClass
  </code></pre>
  
  <p>Anyone knows the linux equivalent? I have tried the below command.</p>
  
  <pre><code>java -agentlib:jdwp=transport=dt_socket,address=8000,server=y,onuncaught=y,suspend=n,launch=jdb MyClass
  </code></pre>
  
  <p>The debugger seems like it connects but it immediately throws an IOError.</p>
  
  <pre><code>Initializing jdb ...
  
  java.io.IOException: Input/output error
  at java.io.FileInputStream.readBytes(Native Method)
  at java.io.FileInputStream.read(FileInputStream.java:272)
  at java.io.BufferedInputStream.read1(BufferedInputStream.java:273)
  at java.io.BufferedInputStream.read(BufferedInputStream.java:334)
  at sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.java:283)
  at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:325)
  at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:177)
  at java.io.InputStreamReader.read(InputStreamReader.java:184)
  at java.io.BufferedReader.fill(BufferedReader.java:154)
  at java.io.BufferedReader.readLine(BufferedReader.java:317)
  at java.io.BufferedReader.readLine(BufferedReader.java:382)
  at com.sun.tools.example.debug.tty.TTY.&lt;init&gt;(TTY.java:751)
  at com.sun.tools.example.debug.tty.TTY.main(TTY.java:1067)
  </code></pre>