[
https://issues.apache.org/jira/browse/AMBARI-15585?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Daniel Gergely updated AMBARI-15585:
------------------------------------
Description:
When throwing an exception in a "catch" block, it should contain the original
exception as a cause.
Otherwise we lose information: the original stacktrace is not obtainable.
This improvement decreases time on investigating issues, since the log contains
the root cause of the exception.
For example in AgentResource:
{noformat}
try {
heartBeatResponse = hh.handleHeartBeat(message);
if (LOG.isDebugEnabled()) {
LOG.debug("Sending heartbeat response with response id " +
heartBeatResponse.getResponseId());
LOG.debug("Response details " + heartBeatResponse);
}
} catch (Exception e) {
LOG.warn("Error in HeartBeat", e); // <-- this is only the message, not
the stack trace
throw new WebApplicationException(500); // <--- cause is lost
}
{noformat}
should be changed to:
{noformat}
try {
heartBeatResponse = hh.handleHeartBeat(message);
if (LOG.isDebugEnabled()) {
LOG.debug("Sending heartbeat response with response id " +
heartBeatResponse.getResponseId());
LOG.debug("Response details " + heartBeatResponse);
}
} catch (Exception e) {
LOG.warn("Error in HeartBeat", e);
throw new WebApplicationException(e,500); // <--- the original exception
is added as cause for the new exception
}
{noformat}
was:
When throwing an exception in a "catch" block, it should contain the original
exception as a cause.
Otherwise we lose information: the original stacktrace is not obtainable.
This improvement decreases time on investigating issues, since the log contains
the root cause of the exception.
For example in AgentResource:
{noformat}
try {
heartBeatResponse = hh.handleHeartBeat(message);
if (LOG.isDebugEnabled()) {
LOG.debug("Sending heartbeat response with response id " +
heartBeatResponse.getResponseId());
LOG.debug("Response details " + heartBeatResponse);
}
} catch (Exception e) {
LOG.warn("Error in HeartBeat", e);
throw new WebApplicationException(500); // <--- cause is lost
}
{noformat}
should be changed to:
{noformat}
try {
heartBeatResponse = hh.handleHeartBeat(message);
if (LOG.isDebugEnabled()) {
LOG.debug("Sending heartbeat response with response id " +
heartBeatResponse.getResponseId());
LOG.debug("Response details " + heartBeatResponse);
}
} catch (Exception e) {
LOG.warn("Error in HeartBeat", e);
throw new WebApplicationException(e,500); // <--- the original exception
is added as cause for the new exception
}
{noformat}
> Losing stacktrace when an exception is cought and an other one is thrown
> ------------------------------------------------------------------------
>
> Key: AMBARI-15585
> URL: https://issues.apache.org/jira/browse/AMBARI-15585
> Project: Ambari
> Issue Type: Improvement
> Reporter: Daniel Gergely
>
> When throwing an exception in a "catch" block, it should contain the original
> exception as a cause.
> Otherwise we lose information: the original stacktrace is not obtainable.
> This improvement decreases time on investigating issues, since the log
> contains the root cause of the exception.
> For example in AgentResource:
> {noformat}
> try {
> heartBeatResponse = hh.handleHeartBeat(message);
> if (LOG.isDebugEnabled()) {
> LOG.debug("Sending heartbeat response with response id " +
> heartBeatResponse.getResponseId());
> LOG.debug("Response details " + heartBeatResponse);
> }
> } catch (Exception e) {
> LOG.warn("Error in HeartBeat", e); // <-- this is only the message, not
> the stack trace
> throw new WebApplicationException(500); // <--- cause is lost
> }
> {noformat}
> should be changed to:
> {noformat}
> try {
> heartBeatResponse = hh.handleHeartBeat(message);
> if (LOG.isDebugEnabled()) {
> LOG.debug("Sending heartbeat response with response id " +
> heartBeatResponse.getResponseId());
> LOG.debug("Response details " + heartBeatResponse);
> }
> } catch (Exception e) {
> LOG.warn("Error in HeartBeat", e);
> throw new WebApplicationException(e,500); // <--- the original
> exception is added as cause for the new exception
> }
> {noformat}
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)