Question: 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?

Answer: 
In your case if ANY Exception is thrown or generated in `doSomething()` it will be caught in the try-catch block because of the `Exception e` you are catching.

`Exception` is the **parent** of all Exceptions. All Exceptions inherit from this class.
Suppose you have this code:

```
   try{
        doSomething();
    }catch(Exception ex){
        System.out.println("Exception:");
        ex.printStackTrace();
    }catch(IndexOutOfBoundsException ex){
         System.out.println("IndexOutOfBoundsException :");
        ex.printStackTrace();
    }

```

You will get a compile error saying 

> 
> Exception *IndexOutIfBounds* is already been caught
> 
> 
> 

That's because every *exceptions* inherits from `Exception` class so the first thing that catch block catches is the Exception because *IndexOutOfBounds* is an Exception so not needed to catch it twice one for the first and one for the second.  

In one case the throws will do its work when you don't declare an exception class after `throws` or in the try-catch.