简体   繁体   中英

Why aren't these throw statements giving me a compiler error?

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;
} 

Shouldn't the compiler require that this method also throws UncategorizedSQLException , DataAccessException ?

Because they are runtime exceptions, which are unchecked meaning that the compiler does not require explicit catching of them.

See this question for more details.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM