Java Exception throws two exceptions out of a method

Description

Java Exception throws two exceptions out of a method


import java.io.DataOutputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.concurrent.LinkedBlockingQueue;

public class Main {
   public static void main(String[] args) {

      try {//from  ww  w. j  a  v a2 s .  co m
         doSomeWork();
      } catch (IOException e) {
         e.printStackTrace();
      } catch (InterruptedException e) {
         e.printStackTrace();
      }
   }

   private static void doSomeWork() throws IOException, InterruptedException {
      LinkedBlockingQueue<String> queue = new LinkedBlockingQueue<String>();

      try {
         FileOutputStream fos = new FileOutputStream("out.log");
         DataOutputStream dos = new DataOutputStream(fos);
         while (!queue.isEmpty()) {
            dos.writeUTF(queue.take());
         }
         dos.close();
      } catch (InterruptedException | IOException e) {
         e.printStackTrace();
         throw e;
      }

   }
}



PreviousNext

Related