⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 errors.java

📁 JAVA 数学程序库 提供常规的数值计算程序包
💻 JAVA
字号:
package jmathlib.core.interpreter;

import java.util.*;
import java.text.MessageFormat;


/**Class used to read and display error strings from a resource bundle*/
public class Errors
{
    /**returns the localised error string for a specific code
    @param errorCode = the code for the error string
    @return the string containing the text*/
    public static String getErrorText(int errorCode)
    {
        String text = "";
        
        ResourceBundle bundle = ResourceBundle.getBundle("jmathLib.resourcebundles.ErrorBundle");
    
        text = bundle.getString(Integer.toString(errorCode));

        return text;
    }

    /**throws an exception with a localised error string
       @param errorCode = the code for the error string*/
    public static void throwMathLibException(int errorCode)
    {
    	String text = getErrorText(errorCode);
        throw (new MathLibException(text));
    	
    }

    /**Throws an exception with an error string. This methode should only
       be used by external functions. Internal classes should use localised
       error messages
       @param errorCode = the error message*/
    public static void throwMathLibException(String errorMessage)
    {
        throw (new MathLibException("ERROR: "+errorMessage));
    }

    /**
     * Throws an exception with an error string. This method should only
     * be used by Parser.java
     * @param errorMessage = the parser error
     */
    public static void throwParserException(String errorMessage)
    {
        throw (new MathLibException("PARSER: "+errorMessage));
    }

    
    /**
     * Throws an exception with an error string. This method should only
     * be used by Usage.java
     * @param errorMessage = the parser error
     */
    public static void throwUsageException(String errorMessage)
    {
        throw (new MathLibException("USAGE: "+errorMessage));
    }

    /**returns the localised error string for a specific code, 
    containing extra data fields
    @param errorCode = the code for the error string
    @param params    = the extra data
    @return the string containing the text*/
    public static String getErrorText(int errorCode, Object[] params)
    {
        String text = "";
        ResourceBundle bundle = ResourceBundle.getBundle("MathLib.ResourceBundles.ErrorBundle");
        text = MessageFormat.format(bundle.getString(Integer.toString(errorCode)), params);

        return text;
    }

    /**throws an exception with a localised error string,
    containing extra data fields
    @param errorCode = the code for the error string
    @param params    = the extra data*/
    public static void throwMathLibException(int errorCode, Object[] params)
    {
    	String text = getErrorText(errorCode, params);
        throw (new MathLibException(text));
    	
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -