Don't throw generic exceptions

This commit is contained in:
Paul Campbell 2018-08-25 08:20:33 +01:00
parent aec69b5a85
commit 0f6af785a5
3 changed files with 83 additions and 4 deletions

View file

@ -0,0 +1,39 @@
/**
* The MIT License (MIT)
*
* Copyright (c) 2018 Paul Campbell
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software
* and associated documentation files (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies
* or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
* AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package net.kemitix.wiser.assertions;
/**
* Assertions caused by errors while parsing mime message content.
*
* @author Paul Campbell (pcampbell@kemitix.net)
*/
public class MimeMessageException extends RuntimeException {
/**
* Create an assertion with a message.
*
* @param message the message
*/
public MimeMessageException(final String message) {
super(message);
}
}

View file

@ -0,0 +1,40 @@
/**
* The MIT License (MIT)
*
* Copyright (c) 2018 Paul Campbell
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software
* and associated documentation files (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies
* or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
* AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package net.kemitix.wiser.assertions;
/**
* Assertions caused by {@link WiserAssertions}.
*
* @author Paul Campbell (pcampbell@kemitix.net)
*/
public class WiserAssertionException extends RuntimeException {
/**
* Create a wrapper for the cause.
*
* @param cause the original exception
*/
public WiserAssertionException(final Throwable cause) {
super(cause);
}
}

View file

@ -187,12 +187,12 @@ public final class WiserAssertions {
* *
* @return the product of the supplier * @return the product of the supplier
*/ */
@SuppressWarnings("illegalCatch") @SuppressWarnings("illegalcatch")
public static <T> T unchecked(final ThrowingSupplier<T> supplier) { public static <T> T unchecked(final ThrowingSupplier<T> supplier) {
try { try {
return supplier.get(); return supplier.get();
} catch (Throwable e) { } catch (Throwable e) {
throw new RuntimeException(e); throw new WiserAssertionException(e);
} }
} }
@ -275,7 +275,7 @@ public final class WiserAssertions {
@SuppressWarnings("npathcomplexity") @SuppressWarnings("npathcomplexity")
private String getMimeMessageBody(final WiserMessage message) private String getMimeMessageBody(final WiserMessage message)
throws IOException, MessagingException { throws IOException, MessagingException {
Object content = getMimeMessage(message).getContent(); final Object content = getMimeMessage(message).getContent();
String result = null; String result = null;
if (content instanceof String) { if (content instanceof String) {
result = (String) content; result = (String) content;
@ -287,7 +287,7 @@ public final class WiserAssertions {
result = getMimeMultipartAsString((MimeMultipart) content); result = getMimeMultipartAsString((MimeMultipart) content);
} }
if (result == null) { if (result == null) {
throw new RuntimeException("Unexpected MimeMessage content"); throw new MimeMessageException("Unexpected MimeMessage content");
} }
return result; return result;
} }