Reputation: 13
public void addTitleRow() throws SQLException{
ResultSet rs = stmt.executeQuery("SELECT * FROM ANY")
log.info ? }
How can I log an exception
declared to be thrown in the method signature? I'm using log4j2
Upvotes: 0
Views: 119
Reputation: 9658
You'll have to catch the exception first in order to to log it. You can suppress it or simply re-throw it later if you wish to.
Here is the code snippet:
Re-Throw Exception:
try {
/* Do Something Here */
} catch (Exception ex) {
log.error("An Exception Has Occurred!", ex);
throw ex;
}
Suppress Exception:
try {
/* Do Something Here */
} catch (Exception ex) {
log.warn("An Exception Has Occurred!", ex);
}
Upvotes: 1