【问题标题】:How can I correct this to get it to compile. I need to use an exception handler and not correct the code我怎样才能更正它以使其编译。我需要使用异常处理程序而不是更正代码
【发布时间】:2014-11-21 21:35:55
【问题描述】:
class Exception3
{
    public static void main(String[] args)
    {
        if (Integer.parseInt(args[0]) == 0)
            throw new Exception("Invalid Command Line Argument");
    }
}
    
    

*错误涉及 OutOfBoundsException

【问题讨论】:

  • 什么是编译器错误?您所说的异常处理程序是指使用 try、catch 语句吗?

标签: user-interface actionlistener settext


【解决方案1】:

你的问题很模糊,但你想做这样的事情吗?我认为这是一个与 java 相关的问题。

这使用 try catch 来尝试解析 int。如果 parseInt 函数抛出异常,则 catch 块将捕获该异常。

 1  class Exception3
 2  {
 3     public static void main(String[] args)
 4     {
 5        try{
 6           if (Integer.parseInt(args[0]) == 0)
 7           {
 8              // its okay?
 9           }
10        }
11        catch(OutOfBoundsException e)
12        {
13            // handle exception
14        }
15     }  

【讨论】:

    猜你喜欢
    • 2017-11-17
    • 1970-01-01
    • 2023-01-02
    • 1970-01-01
    • 2020-03-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-10
    相关资源
    最近更新 更多