Java examples for Object Oriented Design:Exception
Rethrowing the Caught Exception
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; } } }