- java.lang.Object
-
- com.aoapps.lang.util.ErrorPrinter
-
public final class ErrorPrinter extends Object
Prints errors with more detail than a standard printStackTrace() call. Is also able to capture the error into aString
.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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
ErrorPrinter.CustomMessageHandler
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static void
addCustomMessageHandler(ErrorPrinter.CustomMessageHandler handler)
static void
addSql(Throwable t, String sql)
Adds a new mapping between a throwable and the statement that caused it.static void
addSql(Throwable t, PreparedStatement pstmt)
Adds a new mapping between a throwable and the statement that caused it.static void
addSQL(Throwable t, String sql)
Deprecated.Please useaddSql(java.lang.Throwable, java.lang.String)
instead.static void
addSQL(Throwable t, PreparedStatement pstmt)
Deprecated.Please useaddSql(java.lang.Throwable, java.sql.PreparedStatement)
instead.static List<String>
getSql(Throwable t)
Gets the mappings between the given throwable and any statements that caused it.static List<String>
getSQL(Throwable t)
Deprecated.Please usegetSql(java.lang.Throwable)
instead.static String
getStackTraces(Throwable t)
Gets the entire exception report as aString
.static String
getStackTraces(Throwable thrown, Object... extraInfo)
Gets the entire exception report as aString
.static void
printStackTraces(Throwable t)
Deprecated.static void
printStackTraces(Throwable t, Appendable out)
static void
printStackTraces(Throwable thrown, Appendable out, Object... extraInfo)
Prints a detailed error report, including all stack traces, to the provided out.static void
printStackTraces(Throwable t, Object... extraInfo)
Deprecated.
-
-
-
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 fromPreparedStatement
.toString()
, which the PostgreSQL JDBC driver does.
-
addSQL
@Deprecated public static void addSQL(Throwable t, String sql)
Deprecated.Please useaddSql(java.lang.Throwable, java.lang.String)
instead.Adds a new mapping between a throwable and the statement that caused it.- Parameters:
sql
- The SQL statement that caused the exception.
-
addSQL
@Deprecated public static void addSQL(Throwable t, PreparedStatement pstmt)
Deprecated.Please useaddSql(java.lang.Throwable, java.sql.PreparedStatement)
instead.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 fromPreparedStatement
.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.
-
getSQL
@Deprecated public static List<String> getSQL(Throwable t)
Deprecated.Please usegetSql(java.lang.Throwable)
instead.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
@Deprecated public static void printStackTraces(Throwable t)
Deprecated.
-
printStackTraces
@Deprecated public static void printStackTraces(Throwable t, Object... extraInfo)
Deprecated.
-
printStackTraces
public static void printStackTraces(Throwable t, Appendable out)
-
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 isFlushable
, will flush the output.
-
addCustomMessageHandler
public static void addCustomMessageHandler(ErrorPrinter.CustomMessageHandler handler)
-
getStackTraces
public static String getStackTraces(Throwable t)
Gets the entire exception report as aString
. This is not as efficient as directly writing the report due to the extra buffering.
-
-