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 package org.apache.commons.math;
018
019 /**
020 * Exception thrown when an error occurs evaluating a function.
021 * <p>
022 * Maintains an <code>argument</code> property holding the input value that
023 * caused the function evaluation to fail.
024 *
025 * @version $Revision: 670469 $ $Date: 2008-06-23 10:01:38 +0200 (lun, 23 jun 2008) $
026 */
027 public class FunctionEvaluationException extends MathException {
028
029 /** Serializable version identifier. */
030 private static final long serialVersionUID = -2193260774031645876L;
031
032 /** Argument causing function evaluation failure */
033 private double argument = Double.NaN;
034
035 /**
036 * Construct an exception indicating the argument value
037 * that caused the function evaluation to fail.
038 *
039 * @param argument the failing function argument
040 */
041 public FunctionEvaluationException(double argument) {
042 super("Evaluation failed for argument = {0}",
043 new Object[] { Double.valueOf(argument) });
044 this.argument = argument;
045 }
046
047 /**
048 * Constructs an exception with specified formatted detail message.
049 * Message formatting is delegated to {@link java.text.MessageFormat}.
050 * @param argument the failing function argument
051 * @param pattern format specifier
052 * @param arguments format arguments
053 * @since 1.2
054 */
055 public FunctionEvaluationException(double argument,
056 String pattern, Object[] arguments) {
057 super(pattern, arguments);
058 this.argument = argument;
059 }
060
061 /**
062 * Constructs an exception with specified root cause.
063 * Message formatting is delegated to {@link java.text.MessageFormat}.
064 * @param argument the failing function argument
065 * @param cause the exception or error that caused this exception to be thrown
066 * @since 1.2
067 */
068 public FunctionEvaluationException(double argument, Throwable cause) {
069 super(cause);
070 this.argument = argument;
071 }
072
073 /**
074 * Constructs an exception with specified formatted detail message and root cause.
075 * Message formatting is delegated to {@link java.text.MessageFormat}.
076 * @param argument the failing function argument
077 * @param pattern format specifier
078 * @param arguments format arguments
079 * @param cause the exception or error that caused this exception to be thrown
080 * @since 1.2
081 */
082 public FunctionEvaluationException(double argument,
083 String pattern, Object[] arguments,
084 Throwable cause) {
085 super(pattern, arguments, cause);
086 this.argument = argument;
087 }
088
089 /**
090 * Returns the function argument that caused this exception.
091 *
092 * @return argument that caused function evaluation to fail
093 */
094 public double getArgument() {
095 return this.argument;
096 }
097
098 }