1   /*
2    * SPDX-FileCopyrightText: none
3    * SPDX-License-Identifier: CC0-1.0
4    */
5   
6   package dev.metaschema.core.metapath.function;
7   
8   import dev.metaschema.core.metapath.IErrorCode;
9   import edu.umd.cs.findbugs.annotations.NonNull;
10  
11  /**
12   * Represents an error that occurred while performing mathematical operations.
13   */
14  public class ArithmeticFunctionException
15      extends FunctionMetapathError {
16    @NonNull
17    private static final String PREFIX = "FOAR";
18    /**
19     * <a href=
20     * "https://www.w3.org/TR/xpath-functions-31/#ERRFOAR0001">err:FOAR0001</a>:
21     * This error is raised whenever an attempt is made to divide by zero.
22     */
23    public static final int DIVISION_BY_ZERO = 1;
24    /**
25     * <a href=
26     * "https://www.w3.org/TR/xpath-functions-31/#ERRFOAR0002">err:FOAR0002</a>:
27     * This error is raised whenever numeric operations result in an overflow or
28     * underflow.
29     */
30    public static final int OVERFLOW_UNDERFLOW_ERROR = 2;
31  
32    /**
33     * Error message associated with {@link #DIVISION_BY_ZERO}.
34     */
35    public static final String DIVISION_BY_ZERO_MESSAGE = "Division by zero";
36  
37    /**
38     * the serial version UID.
39     */
40    private static final long serialVersionUID = 2L;
41  
42    /**
43     * Constructs a new exception with the provided {@code code}, {@code message},
44     * and no cause.
45     *
46     * @param code
47     *          the error code value
48     * @param message
49     *          the exception message
50     */
51    public ArithmeticFunctionException(int code, String message) {
52      super(IErrorCode.of(PREFIX, code), message);
53    }
54  
55    /**
56     * Constructs a new exception with the provided {@code code}, {@code message},
57     * and {@code cause}.
58     *
59     * @param code
60     *          the error code value
61     * @param message
62     *          the exception message
63     * @param cause
64     *          the original exception cause
65     */
66    public ArithmeticFunctionException(int code, String message, Throwable cause) {
67      super(IErrorCode.of(PREFIX, code), message, cause);
68    }
69  
70    /**
71     * Constructs a new exception with the provided {@code code}, no message, and
72     * the {@code cause}.
73     *
74     * @param code
75     *          the error code value
76     * @param cause
77     *          the original exception cause
78     */
79    public ArithmeticFunctionException(int code, Throwable cause) {
80      super(IErrorCode.of(PREFIX, code), cause);
81    }
82  }