[Minor] Always add exception class in ExceptionHelper.getExceptionMessage()

This commit is contained in:
Robert von Burg 2018-09-10 17:40:26 +02:00
parent afdecd92b7
commit 79af081384
1 changed files with 22 additions and 22 deletions

View File

@ -1,12 +1,12 @@
/* /*
* Copyright 2015 Robert von Burg <eitch@eitchnet.ch> * Copyright 2015 Robert von Burg <eitch@eitchnet.ch>
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -27,34 +27,34 @@ public class ExceptionHelper {
* <p> * <p>
* Returns a message for the given {@link Throwable} * Returns a message for the given {@link Throwable}
* </p> * </p>
* *
* <p> * <p>
* A {@link NullPointerException} only has <code>null</code> as the message so this methods returns the class name * A {@link NullPointerException} only has <code>null</code> as the message so this methods returns the class name
* in such a case * in such a case
* </p> * </p>
* *
* @param t * @param t
* the {@link Throwable} * the {@link Throwable}
* *
* @return the exception as string * @return the exception as string
*/ */
public static String getExceptionMessage(Throwable t) { public static String getExceptionMessage(Throwable t) {
return StringHelper.isEmpty(t.getMessage()) ? t.getClass().getName() : t.getMessage(); return t.getClass().getName() + ": " + t.getMessage();
} }
/** /**
* <p> * <p>
* Returns a message for the given {@link Throwable} * Returns a message for the given {@link Throwable}
* </p> * </p>
* *
* <p> * <p>
* A {@link NullPointerException} only has <code>null</code> as the message so this methods returns the class name * A {@link NullPointerException} only has <code>null</code> as the message so this methods returns the class name
* in such a case * in such a case
* </p> * </p>
* *
* @param t * @param t
* the {@link Throwable} * the {@link Throwable}
* *
* @return the exception as string * @return the exception as string
*/ */
public static String getExceptionMessageWithCauses(Throwable t) { public static String getExceptionMessageWithCauses(Throwable t) {
@ -67,10 +67,10 @@ public class ExceptionHelper {
/** /**
* Formats the given {@link Throwable}'s stack trace to a string * Formats the given {@link Throwable}'s stack trace to a string
* *
* @param t * @param t
* the throwable for which the stack trace is to be formatted to string * the throwable for which the stack trace is to be formatted to string
* *
* @return a string representation of the given {@link Throwable}'s stack trace * @return a string representation of the given {@link Throwable}'s stack trace
*/ */
public static String formatException(Throwable t) { public static String formatException(Throwable t) {
@ -82,10 +82,10 @@ public class ExceptionHelper {
/** /**
* Formats the given {@link Throwable}'s message including causes to a string * Formats the given {@link Throwable}'s message including causes to a string
* *
* @param t * @param t
* the throwable for which the messages are to be formatted to a string * the throwable for which the messages are to be formatted to a string
* *
* @return a string representation of the given {@link Throwable}'s messages including causes * @return a string representation of the given {@link Throwable}'s messages including causes
*/ */
public static String formatExceptionMessage(Throwable t) { public static String formatExceptionMessage(Throwable t) {
@ -93,15 +93,15 @@ public class ExceptionHelper {
return getExceptionMessage(t); return getExceptionMessage(t);
String root = formatExceptionMessage(t.getCause()); String root = formatExceptionMessage(t.getCause());
return getExceptionMessage(t) + "\ncause:\n" + root; return getExceptionMessage(t) + "\ncause: " + root;
} }
/** /**
* Returns the root cause for the given {@link Throwable} * Returns the root cause for the given {@link Throwable}
* *
* @param throwable * @param throwable
* the {@link Throwable} for which to get the root cause * the {@link Throwable} for which to get the root cause
* *
* @return the root cause of the given {@link Throwable} * @return the root cause of the given {@link Throwable}
*/ */
public static Throwable getRootCause(Throwable throwable) { public static Throwable getRootCause(Throwable throwable) {