Question about multiple 'catch'

Posted by chun on Stack Overflow See other posts from Stack Overflow or by chun
Published on 2010-05-07T13:36:45Z Indexed on 2010/05/07 13:38 UTC
Read the original article Hit count: 238

Filed under:

Can anyone tell me why the output of this class is 'xa'? why the other exception won't be caught?

public class Tree {

public static void main(String... args){
    try
    {
        throw new NullPointerException(new Exception().toString());
    } catch (NullPointerException e)
    {
        System.out.print("x");
    }
    catch (RuntimeException e)
    {
        System.out.print("y");
    }
    catch (Exception e)
    {
        System.out.print("z");   
    }        
    finally{System.out.println("a");}
}

}

© Stack Overflow or respective owner

Related posts about java