Here you can find the source of printExceptionMessage(Throwable ex)
Parameter | Description |
---|---|
ex | The throwable to be print |
public static String printExceptionMessage(Throwable ex)
//package com.java2s; public class Main { /**/* w w w .jav a2 s . c o m*/ * Return stack trace of the Throwable ex. This method will return first 5 * lines of the trace * * @param ex * The throwable to be print * @return Stack trace of the throwable * @see printExceptionMessage(Throwable ex, int rowCount) */ public static String printExceptionMessage(Throwable ex) { return printExceptionMessage(ex, 15); } /** * Return stack trace of the Throwable ex * * @param ex * The throwable to be print * @param rowCount * # of lines that should return if -1 then return all stack * trace * @return Stack trace of the throwable */ public static String printExceptionMessage(Throwable ex, int rowCount) { String exMsg = ex.getLocalizedMessage(); StringBuffer buf = new StringBuffer(ex.getClass().getName()); buf.append(": "); if (!isNull(exMsg)) buf.append(exMsg); buf.append(" \r\n"); StackTraceElement[] trace = ex.getStackTrace(); if (rowCount == -1) rowCount = trace.length; for (int i = 0; i < rowCount && i < trace.length; i++) { buf.append("\r\n at "); buf.append(trace[i]); } return buf.toString(); } public static final boolean isNull(Object str) { return (str == null || str.toString().trim().length() == 0); } }