improved try with resources
catching multiple exceptions