Java Exception to String exceptionTypeAndMsg(Exception e)

Here you can find the source of exceptionTypeAndMsg(Exception e)

Description

Displays both the exception class and the message.

License

Open Source License

Declaration

public static String exceptionTypeAndMsg(Exception e) 

Method Source Code

//package com.java2s;
/*-/*from ww w  . j  av  a  2  s. com*/
 *
 *  This file is part of Oracle Berkeley DB Java Edition
 *  Copyright (C) 2002, 2015 Oracle and/or its affiliates.  All rights reserved.
 *
 *  Oracle Berkeley DB Java Edition is free software: you can redistribute it
 *  and/or modify it under the terms of the GNU Affero General Public License
 *  as published by the Free Software Foundation, version 3.
 *
 *  Oracle Berkeley DB Java Edition is distributed in the hope that it will be
 *  useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Affero
 *  General Public License for more details.
 *
 *  You should have received a copy of the GNU Affero General Public License in
 *  the LICENSE file along with Oracle Berkeley DB Java Edition.  If not, see
 *  <http://www.gnu.org/licenses/>.
 *
 *  An active Oracle commercial licensing agreement for this product
 *  supercedes this license.
 *
 *  For more information please contact:
 *
 *  Vice President Legal, Development
 *  Oracle America, Inc.
 *  5OP-10
 *  500 Oracle Parkway
 *  Redwood Shores, CA 94065
 *
 *  or
 *
 *  berkeleydb-info_us@oracle.com
 *
 *  [This line intentionally left blank.]
 *  [This line intentionally left blank.]
 *  [This line intentionally left blank.]
 *  [This line intentionally left blank.]
 *  [This line intentionally left blank.]
 *  [This line intentionally left blank.]
 *  EOF
 *
 */

public class Main {
    /**
     * Displays both the exception class and the message. Use you wnat a 
     * relatively terse display of the exception (i.e. omitting stacktrace).
     * Prefer to use this over exception.getMessage(), as some exceptions have
     * null messages.
     */
    public static String exceptionTypeAndMsg(Exception e) {
        return e.getClass() + " : " + e.getMessage();
    }
}

Related

  1. exceptionToString(final Throwable throwable)
  2. exceptionToString(Throwable e)
  3. exceptionToString(Throwable e)
  4. exceptionToString(Throwable ex)
  5. exceptionToString(Throwable exception)
  6. exceptionWithCause(T exception, Throwable cause)
  7. getErrorMessage(Exception ex)
  8. getErrorMessage(Exception ex)
  9. getErrorMessage(Process process)