001 /*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements. See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License. You may obtain a copy of the License at
008 *
009 * http://www.apache.org/licenses/LICENSE-2.0
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,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017
018 package org.apache.commons.math;
019
020 import org.apache.commons.math.ConvergenceException;
021
022 /**
023 * Error thrown when a numerical computation exceeds its allowed
024 * number of iterations.
025 *
026 * @version $Revision: 746578 $ $Date: 2009-02-21 15:01:14 -0500 (Sat, 21 Feb 2009) $
027 * @since 1.2
028 */
029 public class MaxIterationsExceededException extends ConvergenceException {
030
031 /** Serializable version identifier. */
032 private static final long serialVersionUID = -7821226672760574694L;
033
034 /** Maximal number of iterations allowed. */
035 private final int maxIterations;
036
037 /**
038 * Constructs an exception with specified formatted detail message.
039 * Message formatting is delegated to {@link java.text.MessageFormat}.
040 * @param maxIterations maximal number of iterations allowed
041 */
042 public MaxIterationsExceededException(final int maxIterations) {
043 super("Maximal number of iterations ({0}) exceeded", maxIterations);
044 this.maxIterations = maxIterations;
045 }
046
047 /**
048 * Constructs an exception with specified formatted detail message.
049 * Message formatting is delegated to {@link java.text.MessageFormat}.
050 * @param maxIterations the exceeded maximal number of iterations
051 * @param pattern format specifier
052 * @param arguments format arguments
053 */
054 public MaxIterationsExceededException(final int maxIterations,
055 final String pattern, final Object ... arguments) {
056 super(pattern, arguments);
057 this.maxIterations = maxIterations;
058 }
059
060 /** Get the maximal number of iterations allowed.
061 * @return maximal number of iterations allowed
062 */
063 public int getMaxIterations() {
064 return maxIterations;
065 }
066
067 }