Class ErrorPrinter


  • public class ErrorPrinter
    extends Object
    Prints errors with more detail than a standard printStackTrace() call. Is also able to capture the error into a String.

    TODO: Avoid repetitive sequences of stack traces to reduce total output length.

    TODO: Make an extensible way to register additional error printer features, and automatically load them via ServiceLoader. Maybe spin this off to a microproject if we go this far.

    Author:
    AO Industries, Inc.
    • Method Detail

      • addSQL

        public static void addSQL​(Throwable t,
                                  String sql)
        Adds a new mapping between a throwable and the statement that caused it.
        Parameters:
        sql - The SQL statement that caused the exception.
      • addSQL

        public static void addSQL​(Throwable t,
                                  PreparedStatement pstmt)
        Adds a new mapping between a throwable and the statement that caused it.
        Parameters:
        pstmt - The SQL statement that caused the exception. This must provide the SQL statement from PreparedStatement.toString(), which the PostgreSQL JDBC driver does.
      • getSQL

        public static List<String> getSQL​(Throwable t)
        Gets the mappings between the given throwable and any statements that caused it.
        Returns:
        The SQL statements that caused the exception or an empty list when none.
      • printStackTraces

        public static void printStackTraces​(Throwable thrown,
                                            Appendable out,
                                            Object... extraInfo)
        Prints a detailed error report, including all stack traces, to the provided out. Synchronizes on out to make sure concurrently reported errors will not be mixed. If out is Flushable, will flush the output.
      • getStackTraces

        public static String getStackTraces​(Throwable T)
        Gets the entire exception report as a String. This is not as efficient as directly writing the report due to the extra buffering.
      • getStackTraces

        public static String getStackTraces​(Throwable thrown,
                                            Object... extraInfo)
        Gets the entire exception report as a String. This is not as efficient as directly writing the report due to the extra buffering.