Multiple exception catch block java 8 eclipse

送分小仙女□ 提交于 2019-12-25 05:01:01

问题


I'm getting an unhandled message exception for IOException. As you can see in the pasted code I've handled the IOException. The JDK for both eclipse & the project is Java 8 update 121 so I know catching multiple exceptions is supported. What am I doing wrong?

    try (InputStream inputStream = BatchMessageProperties.class.getClassLoader().
            getResourceAsStream(propertiesFileName)) {

        load(inputStream);
        //need to make sure all properties are present & not null.
        validate(this);

    } catch (IOException | InvalidBatchMessagePropertiesFileException ex) {

        logger.error(ex.getLocalizedMessage());
        ex.printStackTrace();
        throw ex;
    }

回答1:


You do rethrow ex inside your catch block, which may be an IOException, right?



来源:https://stackoverflow.com/questions/43893324/multiple-exception-catch-block-java-8-eclipse

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!