tech.sirwellington.alchemy.arguments.ExceptionMapper Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of alchemy-arguments Show documentation
Show all versions of alchemy-arguments Show documentation
Part of the Alchemy Collection.
Easy, Simple, and Robust argument checking logic
for your Services, Libraries, and Scripts.
/*
* Copyright 2015 SirWellington Tech.
*
* 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 tech.sirwellington.alchemy.arguments;
import java.util.function.Function;
/**
* An {@code ExceptionMapper} decides how to handle a {@link FailedAssertionException}.
*
* It can :
*
* - Supply a new Exception Type that wraps the {@code cause}
*
- Supply a new Exception Type that ignores the {@code cause}
*
- Return null, which causes no exception to be thrown, essentially ignoring the assertion.
*
*
* Behavior #3 may change in the future, as there is no clear use-case for skipping the assertions
* this way.
*
* @author SirWellington
*
* @param
*/
public interface ExceptionMapper extends Function
{
/**
* This identity instance passes the same {@link FailedAssertionException} thrown by the
* {@link AlchemyAssertion}.
*/
ExceptionMapper IDENTITY = ex -> ex;
/**
* Decide how to map the causing exception. You can either return a new Exception that wraps the
* causing exception, or ignore it all-together. You can use the {@link #IDENTITY} to just
* re-throw the {@link FailedAssertionException}.
*
* @param cause The exception thrown by the {@link AlchemyAssertion}
*
* @return Never return a null Exception
*
* @see #IDENTITY
*/
@Override
public Ex apply(FailedAssertionException cause);
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy