8xrl1q
Last Updated: February 25, 2016
·
4.464K
· jaimeph

Sonar: Preserve Stack Trace

Sonar: Preserve Stack Trace

New exception is thrown in catch block, original stack trace may be lost

} catch (XPathExpressionException e) {
    throw new SAMLNoFoundException(e.getMessage(), e.fillInStackTrace());
}

Solution:

} catch (XPathExpressionException e) {
    throw e;
}

2 Responses
Add your response

8595

Nested exception constructor doesn't works for Sonar default rule?

What if you want to explicitely throw SAMLNoFoundException (or WhateverMyException) and not XPathExpressionException?

over 1 year ago ·
8621

Good question, try:

} catch (XPathExpressionException e) {
    throw new SAMLNoFoundException("MESSAGE", e);
}

It does not fail.

over 1 year ago ·