title: Handling the IllegalThreadStateException
body: <pre><code>import java.io.*;
  class Sysexecute
  {
      public static void main(String args[]) throws IOException,InterruptedException,IllegalThreadStateException
      {
          Runtime rt= Runtime.getRuntime();
          Process p=rt.exec("ls");
          System.out.println(p.exitValue());
      }
  }
  </code></pre>
  
  <p>i was learning how to execute system commands in java and this error occured. i tried using throws to negate it but was of no use. please explain the reason and solution</p>
  
  <pre><code>actual error:-
  Exception in thread "main" java.lang.IllegalThreadStateException: process hasn't exited
      at java.lang.UNIXProcess.exitValue(UNIXProcess.java:270)
      at Sysexecute.main(Sysexecute.java:8)
  </code></pre>