public void run(HookContext hookContext) {
    LogHelper console = SessionState.getConsole();

    for (Entry<String, List<List<String>>> entry :
        SessionState.get().getStackTraces().entrySet()) {

      for (List<String> stackTrace : entry.getValue()) {
        // Only print the first line of the stack trace as it contains the error message, and other
        // lines may contain line numbers which are volatile
        // Also only take the string after the first two spaces, because the prefix is a date and
        // and time stamp
        console.printError(StringUtils.substringAfter(
            StringUtils.substringAfter(stackTrace.get(0), " "), " "));
      }
    }
  }
VerifySessionStateStackTracesHook.

Writes the first line of each stack trace collected to the console, to either verify stack
traces were or were not collected.
itests/util/src/main/java/org/apache/hadoop/hive/ql/hooks/VerifySessionStateStackTracesHook.java