FractionException.java

  1. /*
  2.  * Licensed to the Apache Software Foundation (ASF) under one or more
  3.  * contributor license agreements.  See the NOTICE file distributed with
  4.  * this work for additional information regarding copyright ownership.
  5.  * The ASF licenses this file to You under the Apache License, Version 2.0
  6.  * (the "License"); you may not use this file except in compliance with
  7.  * the License.  You may obtain a copy of the License at
  8.  *
  9.  *      http://www.apache.org/licenses/LICENSE-2.0
  10.  *
  11.  * Unless required by applicable law or agreed to in writing, software
  12.  * distributed under the License is distributed on an "AS IS" BASIS,
  13.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14.  * See the License for the specific language governing permissions and
  15.  * limitations under the License.
  16.  */
  17. package org.apache.commons.numbers.fraction;

  18. /**
  19.  * Package private exception class with constants for frequently used messages.
  20.  */
  21. class FractionException extends ArithmeticException {

  22.     /** Error message for overflow during conversion. */
  23.     static final String ERROR_CONVERSION_OVERFLOW = "Overflow trying to convert %s to fraction (%d/%d)";
  24.     /** Error message when iterative conversion fails. */
  25.     static final String ERROR_CONVERSION = "Unable to convert %s to fraction after %d iterations";
  26.     /** Error message for zero-valued denominator. */
  27.     static final String ERROR_ZERO_DENOMINATOR = "Denominator must be different from 0";
  28.     /** Error message for divide by zero. */
  29.     static final String ERROR_DIVIDE_BY_ZERO = "The value to divide by must not be zero";

  30.     /** Serializable version identifier. */
  31.     private static final long serialVersionUID = 201701191744L;

  32.     /**
  33.      * Create an exception where the message is constructed by applying
  34.      * {@link String#format(String, Object...)}.
  35.      *
  36.      * @param message  the exception message format string
  37.      * @param formatArguments the arguments for formatting the message
  38.      */
  39.     FractionException(String message, Object... formatArguments) {
  40.         super(String.format(message, formatArguments));
  41.     }

  42.     /**
  43.      * Create an exception with the specified message.
  44.      *
  45.      * @param message  the exception message
  46.      */
  47.     FractionException(String message) {
  48.         super(message);
  49.     }
  50. }