hi, looking at this example code:

public void writeList() {
    PrintWriter out = null;

    try {
        System.out.println("Entering try statement");
        out = new PrintWriter(
	                  new FileWriter("OutFile.txt"));
            for (int i = 0; i < SIZE; i++)
                out.println("Value at: " + i + " = " 
                             + vector.elementAt(i));
    } catch (ArrayIndexOutOfBoundsException e) {
         System.err.println("Caught " 
                     + "ArrayIndexOutOfBoundsException: " 
                     +   e.getMessage());
    } catch (IOException e) {
         System.err.println("Caught IOException: " 
                             +  e.getMessage());
    } finally {
         if (out != null) {
             System.out.println("Closing PrintWriter");
         else {
             System.out.println("PrintWriter not open");

if say, for example, FileWriter() throws an IOException.
Am i write to say that the call stack will be:

i.e the runtime will check for the handler in FilerWriter(), then PrintWriter(), and finally in WriteList()


In principal: yes, although the absence/presence of a "throws" declaration in the method signatures determines whether the Exception is propogated.

(On re-reading I see that that was a bit cryptic. Here's a better answer.)
Every method must either catch the Exception or pass it up the stack - which it can only do if its declaration includes "throws ...". If you don't either catch the Exception or throw it up the stack then that's an error.
In this case each of those methods declares that it can throw ther Execption, and does not catch it, so it gets propogated as you supposed.

This article has been dead for over six months. Start a new discussion instead.