001/*
002 * ============================================================================
003 * Copyright © 2002-2020 by Thomas Thrien.
004 * All Rights Reserved.
005 * ============================================================================
006 * Licensed to the public under the agreements of the GNU Lesser General Public
007 * License, version 3.0 (the "License"). You may obtain a copy of the License at
008 *
009 *      http://www.gnu.org/licenses/lgpl.html
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
013 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
014 * License for the specific language governing permissions and limitations
015 * under the License.
016 */
017
018package org.tquadrat.foundation.exception;
019
020import static org.apiguardian.api.API.Status.STABLE;
021import static org.tquadrat.foundation.lang.Objects.isNull;
022
023import java.io.Serial;
024
025import org.apiguardian.api.API;
026import org.tquadrat.foundation.annotation.ClassVersion;
027
028/**
029 *  This is a specialized implementation for the
030 *  {@link IllegalArgumentException}
031 *  that is meant as the root for a hierarchy of exceptions caused by
032 *  validation errors.
033 *
034 *  @extauthor Thomas Thrien - thomas.thrien@tquadrat.org
035 *  @version $Id: ValidationException.java 1023 2022-03-05 23:56:16Z tquadrat $
036 *  @since 0.0.5
037 *
038 *  @UMLGraph.link
039 */
040@ClassVersion( sourceVersion = "$Id: ValidationException.java 1023 2022-03-05 23:56:16Z tquadrat $" )
041@API( status = STABLE, since = "0.0.5" )
042public class ValidationException extends IllegalArgumentException
043{
044        /*-----------*\
045    ====** Constants **========================================================
046        \*-----------*/
047    /**
048     *  The message text for a validation error.
049     */
050    public static final String MSG_ValidationFailed = "Validation failed";
051
052        /*------------------------*\
053    ====** Static Initialisations **===========================================
054        \*------------------------*/
055    /**
056     *  The serial version UID for objects of this class: {@value}.
057     *
058     * @hidden
059     */
060    @Serial
061    private static final long serialVersionUID = 1174360235354917591L;
062
063        /*--------------*\
064    ====** Constructors **=====================================================
065        \*--------------*/
066    /**
067     *  Creates a new {@code ValidationException} instance.
068     */
069    public ValidationException()
070    {
071        super( MSG_ValidationFailed );
072    }   //  ValidationException()
073
074    /**
075     *  Creates a new {@code ValidationException} instance.
076     *
077     *  @param  message The message that provides details on the failed
078     *      validation.
079     */
080    public ValidationException( final String message )
081    {
082        super( isNull( message ) || message.isEmpty() ? MSG_ValidationFailed : message );
083    }   //  ValidationException()
084
085    /**
086     *  Creates a new {@code ValidationException} instance.
087     *
088     *  @param  message The message that provides details on the failed
089     *      validation.
090     *  @param  cause   The exception that is related to the validation error.
091     */
092    public ValidationException( final String message, final Throwable cause )
093    {
094        super( isNull( message ) || message.isEmpty() ? MSG_ValidationFailed : message, cause );
095    }   //  ValidationException()
096
097    /**
098     *  Creates a new {@code ValidationException} instance.
099     *
100     *  @param  cause   The exception that is related to the validation error.
101     */
102    public ValidationException( final Throwable cause )
103    {
104        super( MSG_ValidationFailed, cause );
105    }   //  ValidationException()
106}
107//  class ValidationException
108
109/*
110 *  End of File
111 */