public static String stackTraceToString(String message, Throwable t) {
		StringBuilder sb = new StringBuilder();

		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		PrintStream ps = new PrintStream(baos);

		if (message != null) {
			ps.println(message);
		}
		else {
			String throwableMessage = t.getMessage();
			if (throwableMessage != null) {
				ps.println(throwableMessage);
			}
		}

		t.printStackTrace(ps);
		sb.append(baos.toString());
		ps.close();
		try {
			baos.close();
		}
		catch (IOException e) {
			// shouldn't happen--not really connected to the system
		}

		return sb.toString();
	}
Turns the given {@link Throwable} into a String version of its
{@link Throwable#printStackTrace()} method.

@param message the preferred message to use.  If null, the throwable message will be used
@param t the throwable
@return the string
Ghidra/Framework/Utility/src/main/java/utilities/util/reflection/ReflectionUtilities.java