Java,Eclipse不接受自定义异常

时间:2012-06-21 23:27:19

标签: java

Eclipse抱怨我下面的catch声明

public class NaturalLanguageMultiply
{
    public class WrongMultiplierException extends Exception
    {

    }

    private static int toInt( String number ) throws WrongMultiplierException 
    {
        // removed for clarity
                try
               {
                    String numberKey = scanner.next();
                    if ( numberMap.containsKey( numberKey ) )
                    {
                        multiplier += ( Integer ) numberMap.get( numberKey );
                    }
                    else
                    {
                        throw new WrongMultiplierException();
                    }
                }

它抱怨以下问题:

Syntax error on tokens

                catch ( WrongMultiplierException );
                {

                }
            }

另外,为什么StackOverflow会一直在问:你的帖子没有太多的上下文来解释代码部分;请更清楚地解释您的情景。我在FAQ或帮助中找不到答案。

3 个答案:

答案 0 :(得分:6)

catch ( WrongMultiplierException );
{
}

catch ( WrongMultiplierException wme)
{
}

答案 1 :(得分:1)

你有一个;在catch的右括号之后,这是语法错误。

答案 2 :(得分:1)

在此行catch ( WrongMultiplierException );中,您必须添加例外引用名称并删除;。正确版本:catch ( WrongMultiplierException ex)

相关问题