Java Exception Message exceptionMessage(Throwable e)

Here you can find the source of exceptionMessage(Throwable e)

Description

exception Message

License

Open Source License

Declaration

public static String exceptionMessage(Throwable e) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2013 Luigi Sgro. 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:/* w  w w . ja va 2 s  . c o  m*/
 *     Luigi Sgro - initial API and implementation
 ******************************************************************************/

public class Main {
    public static String exceptionMessage(Throwable e) {
        StringBuilder buffer = new StringBuilder();
        buffer.append(extractMessage(e));
        if (e.getCause() != null) {
            buffer.append(" [cause: ").append(extractMessage(e.getCause())).append("]");
        }
        return buffer.toString();
    }

    private static String extractMessage(Throwable e) {
        if (e.getMessage() != null) {
            return e.getMessage();
        } else {
            return e.toString();
        }
    }
}

Related

  1. exception(Throwable e)
  2. exception(Throwable t)
  3. exceptionMessage(Object... strings)
  4. exceptionSimpleDesc(final Exception e)
  5. exceptionStackTrace(Exception ex)