io.rxmicro.common.CheckedWrapperException Maven / Gradle / Ivy
Show all versions of rxmicro-common Show documentation
/*
* Copyright (c) 2020. https://rxmicro.io
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.rxmicro.common;
import io.rxmicro.common.util.Formats;
/**
* Wrapper for checked exceptions.
*
* @author nedis
* @see io.rxmicro.common.util.Exceptions
* @since 0.1
*/
public final class CheckedWrapperException extends RxMicroException {
/**
* Creates a new {@link CheckedWrapperException} instance with error message and cause.
*
*
* (FYI: This constructor uses {@link Formats#format(String, Object...)} method to format error message.)
*
* @param cause the cause (which is saved for later retrieval by the {@link #getCause()} method).
* @param message the error message template
* @param args the error message template arguments
* @throws NullPointerException if the error message template or cause is {@code null}
* @throws IllegalArgumentException if detected a redundant placeholder or missing argument
*/
public CheckedWrapperException(final Throwable cause,
final String message,
final Object... args) {
super(cause, message, args);
}
/**
* Creates a new {@link CheckedWrapperException} instance with cause only.
*
* @param cause the cause (which is saved for later retrieval by the {@link #getCause()} method).
* @throws NullPointerException if the cause is {@code null}
*/
public CheckedWrapperException(final Throwable cause) {
super(cause);
}
/**
* Returns {@code true} if current instance contains a cause one of the specified throwable class.
*
* @param throwableClass the specified throwable class
* @return {@code true} if current instance contains a cause one of the specified throwable class
*/
public boolean isCause(final Class extends Throwable> throwableClass) {
return getCause() != null && throwableClass.isAssignableFrom(getCause().getClass());
}
}