为什么这些throw语句不会给我编译错误?

时间:2015-06-30 21:39:42

标签: java exception exception-handling

public String runQuery(String q) throws JsonGenerationException, JsonMappingException   
 {   
    Graph g = null;
            try {
                g = jdbcTemplate.query(q, new Neo4jGraphResultSetExtractor());
            } catch (DataAccessException e) {

                if (e instanceof UncategorizedSQLException)
                    {
                    //Invalid cypher query
                    throw (UncategorizedSQLException)e;
                    }

                else throw e; 
            }

    json = g.toJson(); //throws JsonGenerationException, JsonMappingException
    return json;
} 

编译器是否应该要求此方法也抛出UncategorizedSQLExceptionDataAccessException

1 个答案:

答案 0 :(得分:0)

因为它们是运行时异常,未选中意味着编译器不需要显式捕获它们。

See this question for more details.