Makes a string representation of the exception's stack trace, or "(null)", if the
exception is null.

<p>This method makes a best effort and never fails.

@param e The exception to stringify.
@return A string with exception name and call stack.
519346
public static String stringifyException(final Throwable e) {
		if (e == null) {
			return STRINGIFIED_NULL_EXCEPTION;
		}

		try {
			StringWriter stm = new StringWriter();
			PrintWriter wrt = new PrintWriter(stm);
			e.printStackTrace(wrt);
			wrt.close();
			return stm.toString();
		}
		catch (Throwable t) {
			return e.getClass().getName() + " (error while printing stack trace)";
		}
	}
168456
private static String __getStackTrace(Throwable throwable) {
        StringWriter stringWriter = new StringWriter();
        throwable.printStackTrace(new PrintWriter(stringWriter));

        return stringWriter.toString();
    }
304018
public void printStackToDebug() {
        Throwable t = new Throwable();
        StackTraceElement[] ste = t.getStackTrace();

        int start = (ste.length > 6) ? 6 : ste.length;
        for (int i = start; i >= 1; i--) {
            Tr.debug(tc, "Calling Stack Element[" + i + "]: " + ste[i]);
        }
    }
1026161
public static String getTrimmedStackTrace(Throwable exception) {
        List<String> trimmedStackTraceLines = getTrimmedStackTraceLines(exception);
        if (trimmedStackTraceLines.isEmpty()) {
            return getFullStackTrace(exception);
        }

        StringBuilder result = new StringBuilder(exception.toString());
        appendStackTraceLines(trimmedStackTraceLines, result);
        appendStackTraceLines(getCauseStackTraceLines(exception), result);
        return result.toString();
    }
12514
static ExceptionInfo processStackTrace(StackTrace exception) {
    if (exception == null) {
      return null;
    }
    // Escape any special HTML characters in the exception that would otherwise break the HTML
    // rendering (e.g. the angle brackets around the default toString() for enums).
    String message = StringEscapeUtils.escapeHtml4(exception.toString());

    // Newline characters are usually stripped out by the parsing code in
    // {@link StackTrace#from(String)}, but they can sometimes remain (e.g. when the stack trace
    // is not in an expected format).  This replacement needs to be done after any HTML escaping.
    message = message.replace("\n", "<br/>");

    List<String> lines = exception.getElements()
        .stream()
        .map(element -> "&nbsp;&nbsp;&nbsp;&nbsp;at " + element.toString())
        .collect(toList());
    while (exception.getCause() != null) {
      exception = exception.getCause();
      String causeMessage = StringEscapeUtils.escapeHtml4(exception.toString());
      lines.add("Caused by: " + causeMessage.replace("\n", "<br/>"));
    }
    return new ExceptionInfo(message, lines);
  }
701713
public static String buildStackTraceString(final Throwable ex) {
        final StringBuilder context = new StringBuilder(ex.toString());
        final StringWriter sw = new StringWriter();
        ex.printStackTrace(new PrintWriter(sw, true));
        context.append('\n');
        context.append(sw.toString());

        return context.toString();
    }
61637
public static String stackTraceText(@NotNull Throwable t) {
		StringBuilderWriter stringWriter = new StringBuilderWriter();
		t.printStackTrace(new PrintWriter(stringWriter)); // NOSONAR
		return stringWriter.toString();
	}
129648
static public String exceptionSummary(JMSException e){
		Throwable cause = e.getCause();
		Exception linked = e.getLinkedException();
		return "JMSException: " + e.getMessage() 
				+ ", error code: " + e.getErrorCode()
				+ ", linked exception: " 
				+ (linked == null ? null : (linked.getClass().getName() + " - " + linked.getMessage()))
				+ ", cause: " 
				+ (cause == null ? null : (cause.getClass().getName() + " - " + cause.getMessage()));
	}
900811
public static String getExceptionMessage(Throwable exception)
    {
        StringWriter        out = new StringWriter();
        exception.printStackTrace(new PrintWriter(out));
        BufferedReader      in = new BufferedReader(new StringReader(out.toString()));
        try
        {
            StringBuilder       str = new StringBuilder();
            for(;;)
            {
                String  line = in.readLine();
                if ( line == null )
                {
                    break;
                }
                if ( str.length() > 0 )
                {
                    str.append(", ");
                }
                str.append(line);
            }
            return str.toString();
        }
        catch ( IOException e )
        {
            // ignore
        }
        return "n/a";
    }
46930
static void showError(Exception e) {
    String stackTrace = org.languagetool.tools.Tools.getFullStackTrace(e);
    String msg = "<html><p style='width: 600px;'>" + StringTools.escapeHTML(stackTrace);
    JOptionPane.showMessageDialog(null, msg, "Error", JOptionPane.ERROR_MESSAGE);
    e.printStackTrace();
  }
793566
protected String getErrorMessage(Exception e) {

		String ip;
		try {
			ip = InetAddress.getByName(server.split(":")[0]).getHostAddress();
		}
		catch (UnknownHostException e1) {
			ip = null;
			// throw new RuntimeException(e1.getMessage(), e1);
		}
		String message = "server:" + server + " ip:" + ip + " messsage:" + e.getMessage();
		logger.error(message);
		return message;
	}
75767
public static void queueException(final Throwable e) {
		if (e != null) {
			try {
				LogAppender<LogEvent> appender = LogManager.getAppender();
	
				if (appender != null) {
					appender.append(LogEvent.newBuilder().level("ERROR").message(e.getMessage()).exception(e).build());
				}
			} catch (Throwable t) {
				LOGGER.info("Unable to queue exception to Stackify Log API service: {}", e, t);
			}
		}
	}
1131681
public static void printStackTrace(Throwable e, PrintWriter out)
  {
    StackTraceElement lastHead = null;

    ClassLoader loader = SimpleLoader.create(WorkDir.getLocalWorkDir());
    
    while (true) {
      if (e.getMessage() != null)
        out.println(e.getClass().getName() + ": " + e.getMessage());
      else
        out.println(e.getClass().getName());

      StackTraceElement []trace = e.getStackTrace();
      StackTraceElement nextHead = trace.length > 0 ? trace[0] : null;

      for (int i = 0; i < trace.length; i++) {
        if (trace[i].equals(lastHead))
          break;

        out.print("\tat ");

        printStackTraceElement(trace[i], out, loader);
      }

      lastHead = nextHead;

      Throwable cause = e.getCause();

      if (cause != null) {
        out.print("Caused by: ");
        e = cause;
      }
      else
        break;
    }
  }
94509
private static String getExceptionMessage(final String[] exception) {
        StringBuffer buff = new StringBuffer();
        for (int i = 0; i < exception.length; i++) {
            buff.append(exception[i]);
        }
        return buff.toString();
    }
1066361
public String createErrorMessage(RecognitionException e)
	        {
	        StringBuilder message = new StringBuilder();
	                message.append( source + ":"+e.line+":"+e.charPositionInLine+" ");
	                if ( e instanceof MismatchedTokenException ) {
	                        MismatchedTokenException mte = (MismatchedTokenException)e;
	                        message.append("mismatched token: "+
	                                                           e.token+
	                                                           "; expecting type "+
	                                                           tokenNames[mte.expecting]);
	                }
	                else if ( e instanceof MismatchedTreeNodeException ) {
	                        MismatchedTreeNodeException mtne = (MismatchedTreeNodeException)e;
	                        message.append("mismatched tree node: "+
	                                                           mtne.node+
	                                                           "; expecting type "+
	                                                           tokenNames[mtne.expecting]);
	                }
	                else if ( e instanceof NoViableAltException ) {
	                        NoViableAltException nvae = (NoViableAltException)e;
	            message.append( "Unexpected token '" + e.token.getText() + "'" );
	                        /*
	                        message.append("decision=<<"+nvae.grammarDecisionDescription+">>"+
	                                                           " state "+nvae.stateNumber+
	                                                           " (decision="+nvae.decisionNumber+
	                                                           ") no viable alt; token="+
	                                                           e.token);
	                                                           */
	                }
	                else if ( e instanceof EarlyExitException ) {
	                        EarlyExitException eee = (EarlyExitException)e;
	                        message.append("required (...)+ loop (decision="+
	                                                           eee.decisionNumber+
	                                                           ") did not match anything; token="+
	                                                           e.token);
	                }
	                else if ( e instanceof MismatchedSetException ) {
	                        MismatchedSetException mse = (MismatchedSetException)e;
	                        message.append("mismatched token '"+
	                                                           e.token+
	                                                           "' expecting set "+mse.expecting);
	                }
	                else if ( e instanceof MismatchedNotSetException ) {
	                        MismatchedNotSetException mse = (MismatchedNotSetException)e;
	                        message.append("mismatched token '"+
	                                                           e.token+
	                                                           "' expecting set "+mse.expecting);
	                }
	                else if ( e instanceof FailedPredicateException ) {
	                        FailedPredicateException fpe = (FailedPredicateException)e;
	                        message.append("rule "+fpe.ruleName+" failed predicate: {"+
	                                                           fpe.predicateText+"}?");
	        }
	                   return message.toString();
	        }
1067201
public static String toStackTraceString(String firstLine, StackTraceElement[] stack)
  {
    //add the class name and any message passed to constructor
    final StringBuilder result = new StringBuilder(firstLine);
    //result.append(aThrowable.toString());
    final String NEW_LINE = System.getProperty("line.separator");
    result.append(NEW_LINE);

    //add each element of the stack trace
    for (StackTraceElement element : stack ){
      result.append("  at ");
      result.append( element );
      result.append( NEW_LINE );
    }
    return result.toString();
  }
157923
private String printStackTrace(Object[] stackTrace) {
        StringBuilder output = new StringBuilder();
        for (Object line : stackTrace) {
            output.append(line);
            output.append(newline);
        }
        return output.toString();
    }