Check for null message when getting the exception message

This commit is contained in:
nathan 2017-08-17 15:25:21 +02:00
parent 545fef3a7e
commit c6ada706d6

View File

@ -304,15 +304,20 @@ class OS {
/** /**
* @return the first line of the exception message from 'throwable' * @return the first line of the exception message from 'throwable', or the type if there was no message.
*/ */
public static public static
String getExceptionMessage(final Throwable throwable) { String getExceptionMessage(final Throwable throwable) {
String message = throwable.getMessage(); String message = throwable.getMessage();
if (message != null) {
int index = message.indexOf(OS.LINE_SEPARATOR); int index = message.indexOf(OS.LINE_SEPARATOR);
if (index > -1) { if (index > -1) {
message = message.substring(0, index); message = message.substring(0, index);
} }
} else {
message = throwable.getClass()
.getSimpleName();
}
return message; return message;
} }