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.math;
18
19 /**
20 * Exception thrown when an error occurs evaluating a function.
21 * <p>
22 * Maintains an <code>argument</code> property holding the input value that
23 * caused the function evaluation to fail.
24 *
25 * @version $Revision: 620312 $ $Date: 2008-02-10 12:28:59 -0700 (Sun, 10 Feb 2008) $
26 */
27 public class FunctionEvaluationException extends MathException {
28
29 /** Serializable version identifier. */
30 private static final long serialVersionUID = -7619974756160279127L;
31
32 /** Argument causing function evaluation failure */
33 private double argument = Double.NaN;
34
35 /**
36 * Construct an exception indicating the argument value
37 * that caused the function evaluation to fail.
38 *
39 * @param argument the failing function argument
40 */
41 public FunctionEvaluationException(double argument) {
42 super("Evaluation failed for argument = {0}",
43 new Object[] { new Double(argument) });
44 this.argument = argument;
45 }
46
47 /**
48 * Construct an exception using the given argument and message
49 * text.
50 *
51 * @param argument the failing function argument
52 * @param message the exception message text
53 * @deprecated as of 1.2, replaced by {@link #FunctionEvaluationException(double, String, Object[])}
54 */
55 public FunctionEvaluationException(double argument, String message) {
56 super(message);
57 this.argument = argument;
58 }
59
60 /**
61 * Constructs an exception with specified formatted detail message.
62 * Message formatting is delegated to {@link java.text.MessageFormat}.
63 * @param argument the failing function argument
64 * @param pattern format specifier
65 * @param arguments format arguments
66 * @since 1.2
67 */
68 public FunctionEvaluationException(double argument,
69 String pattern, Object[] arguments) {
70 super(pattern, arguments);
71 this.argument = argument;
72 }
73
74 /**
75 * Construct an exception with the given argument, message and root cause.
76 *
77 * @param argument the failing function argument
78 * @param message descriptive error message
79 * @param cause root cause.
80 * @deprecated as of 1.2, replaced by {@link #FunctionEvaluationException(double, String, Object[], Throwable)}
81 */
82 public FunctionEvaluationException(double argument,
83 String message, Throwable cause) {
84 super(message, cause);
85 this.argument = argument;
86 }
87
88 /**
89 * Constructs an exception with specified root cause.
90 * Message formatting is delegated to {@link java.text.MessageFormat}.
91 * @param argument the failing function argument
92 * @param cause the exception or error that caused this exception to be thrown
93 * @since 1.2
94 */
95 public FunctionEvaluationException(double argument, Throwable cause) {
96 super(cause);
97 this.argument = argument;
98 }
99
100 /**
101 * Constructs an exception with specified formatted detail message and root cause.
102 * Message formatting is delegated to {@link java.text.MessageFormat}.
103 * @param argument the failing function argument
104 * @param pattern format specifier
105 * @param arguments format arguments
106 * @param cause the exception or error that caused this exception to be thrown
107 * @since 1.2
108 */
109 public FunctionEvaluationException(double argument,
110 String pattern, Object[] arguments,
111 Throwable cause) {
112 super(pattern, arguments, cause);
113 this.argument = argument;
114 }
115
116 /**
117 * Returns the function argument that caused this exception.
118 *
119 * @return argument that caused function evaluation to fail
120 */
121 public double getArgument() {
122 return this.argument;
123 }
124
125 }