Rethrowing the Caught Exception - Java Object Oriented Design

Java examples for Object Oriented Design:Exception

Description

Rethrowing the Caught Exception

Demo Code

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 {// www.j av a  2  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<>();
    try {
      FileOutputStream fos = new FileOutputStream("out.log");
      DataOutputStream dos = new DataOutputStream(fos);
      while (!queue.isEmpty()) {
        dos.writeUTF(queue.take());
      }
    } catch (InterruptedException | IOException e) {
      e.printStackTrace();
      throw e;
    }
  }
}

Related Tutorials