In Log4j 2, you can use Logger.catching() to log a stacktrace from an exception that was caught.
try {
String msg = messages[messages.length];
logger.error("An exception should have been thrown");
} catch (Exception ex) {
logger.catching(ex);
}