title: Java method silently fails. There are now Throwables, no crashes, nothing I can find
body: <p>I am dealing with a Java method that stops working silently. I've put catches around the method and am trying to catch Throwables, but I don't catch anything. I also tried debugging, but the method just stops working on a line for no reason.</p>
  
  <p>I have a simple client-server app and the client sends a file to the server. Here's the relevant code for the server handling the file transfer:</p>
  
  <pre><code>public void receiveFile(String filePath) throws IOException
      {
          InputStream inStream = null;
          FileOutputStream outStream = null;
  
          try {
              inStream = fSocket.getInputStream();
  
              File f = new File(filePath);
              if (f.exists()) {
                  throw new FileAlreadyExistsException(filePath + " already exists!");
              }
  
              outStream = new FileOutputStream(filePath);
  
              byte[] bytes = new byte[8192];
  
              int count;
              while ((count = inStream.read(bytes)) &gt; 0) {
                  outStream.write(bytes, 0, count);
              }
          } catch (Throwable t) {
              System.out.println("Error when fetching file");
              System.out.println(t.toString());
          } finally {
              if (outStream != null) outStream.close();
          }
      }
  </code></pre>
  
  <p>I can get the file fine. When I look in my files, the file has been transfered and is complete. For some reason, as soon as the transfer is done, my problem comes with the line <code>while ((count = inStream.read(bytes)) &gt; 0)</code>. I tried debugging, and when it gets to that line when the transfer is done, it just stops. I have no idea where the execution goes. <a href="https://imgur.com/2TvGh2y" rel="nofollow noreferrer">Here's a gif of the issue</a>.</p>
  
  <p>Does anyone know what this could be? I am using threads if that's of any relevance.</p>
  
  <p>Here's the client code:</p>
  
  <pre><code>public void sendFile(String fileName) throws IOException
      {
          InputStream inStream = null;
          OutputStream outStream = null;
  
          try {
              File file = new File(fileName);
              byte[] buffer = new byte[8192];
              inStream = new FileInputStream(file);
              outStream = fSocket.getOutputStream();
  
              int count;
              while ((count = inStream.read(buffer)) &gt; 0) {
                  outStream.write(buffer, 0, count);
              }
              System.out.println("Done sending data");
          } catch (IOException e) {
              System.out.println(e.toString());
          } finally {
              if (outStream != null) outStream.flush();
              if (inStream != null) inStream.close();
          }
      }
  </code></pre>