Here you can find the source of getErrorMessage(Exception ex)
public static String getErrorMessage(Exception ex)
//package com.java2s; /******************************************************************************* * Copyright (c) 2013 jialiang.//from w w w . ja v a 2s . co m * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * Ben Xu, xufengbing@gmail.com - initial API and implementation * jialiang, lantianjialiang@gmail.com - add copy right and fix warning ******************************************************************************/ import java.io.IOException; import java.io.PrintWriter; import java.io.StringWriter; public class Main { public static String getErrorMessage(Exception ex) { StringWriter stringWriter = new StringWriter(); ex.printStackTrace(new PrintWriter(stringWriter)); String returnStr = new String(stringWriter.getBuffer()); stringWriter.flush(); try { stringWriter.close(); } catch (IOException e) { e.printStackTrace(); } return returnStr; } }