Throwing exceptions as well as catching exceptions?

Posted by Eric S on Stack Overflow See other posts from Stack Overflow or by Eric S
Published on 2013-06-26T21:52:57Z Indexed on 2013/06/26 22:21 UTC
Read the original article Hit count: 413

I was wondering how Java takes the following scenario

public static void main(String[] args) throws IndexOutOfBoundsException, CoordinateException, MissionException, SQLException, ParserConfigurationException {
    try {
        doSomething();
    } catch (Exception e) {
        e.printStackTrace();
    } 
}

In the above code, I am declaring the main function to throw many different exceptions, but inside the function, I am catching the generic Exception. I am wondering how java takes this internally? I.e., say doSomething() throws an IndexOutOfBounds exception, will the e.printStackTrace() get called in the last catch (Exception e) {...} block?

I know if an exception not declared in the throws area of the function gets thrown, the try/catch will handle it, but what about exceptions mentioned in the declaration?

© Stack Overflow or respective owner

Related posts about java

Related posts about exception