0
 public class XGetProgramGuideDirectTestControllerCmdImpl extends ControllerCommandImpl implements XGetProgramGuideDirectTestControllerCmd {
    public final String CLASSNAME = this.getClass().getName();
    public void performExecute() throws ECException { /* code is here*/ }

    private void callUSInterface() throws ECException { /* code is here*/ }

    private void callDEInterface() throws ECException { /* code is here*/ }

    private void callUKInterface() throws ECException { /* code is here*/ }

    public void setRequestProperties(TypedProperty req) throws ECException { /* code is here*/ }

    private void displayResponse(StringBuffer testResult) { /* code is here*/ }

    public static void main(String[] args) {
        XGetProgramGuideDirectTestControllerCmdImpl PGDirTestController = new XGetProgramGuideDirectTestControllerCmdImpl();
        PGDirTestController.performExecute();
    }

}

我只是尝试将此应用程序作为 Eclipse-RAD 中的 java 应用程序运行,public static void main(String[] args)但它给了我一个错误:

Exception in thread "main" java.lang.Error: Unresolved compilation problem: 
    Unhandled exception type ECException 

上:

PGDirTestController.performExecute();

请放轻松,我对Java还是很陌生。

4

2 回答 2

3

既然你声明:

public void performExecute() throws ECException 

然后你被迫处理ECException

所以当你调用它时,你应该用它包围它try-catch或声明你调用它的方法到throw异常:

public static void main(String[] args) {
      XGetProgramGuideDirectTestControllerCmdImpl PGDirTestController = new 
               XGetProgramGuideDirectTestControllerCmdImpl();
      try {
          PGDirTestController.performExecute();
      } catch(ECException e) { 
            e.printStackTrace();
            //Handle the exception!
        }
}

或者

public static void main(String[] args) throws ECException {
     XGetProgramGuideDirectTestControllerCmdImpl PGDirTestController = new 
              XGetProgramGuideDirectTestControllerCmdImpl();
     PGDirTestController.performExecute();
}
于 2013-07-11T13:31:29.343 回答
1

首先,变量应该按照Java 约定以小写开头,否则会造成混淆:

XGetProgramGuideDirectTestControllerCmdImpl pGDirTestController = new XGetProgramGuideDirectTestControllerCmdImpl();

关于您的问题,未处理的异常类型意味着此方法会引发不是 RuntimeException 的异常并且您没有处理它。在 Java 中,您必须显式捕获不是 RuntimeException 子级的所有异常。

try {
    pGDirTestController.performExecute();
} catch (final ECException e) {
    // Do whatever you need to do if this exception is thrown
}

ECException每当抛出an 时,将执行 catch 部分。您应该在此处添加代码以处理抛出此异常时的处理方式。我强烈建议您不要将此 catch 留空,因为如果抛出异常,您将永远不会知道。

如果您将使用 Java,我强烈建议您获取 Java 书籍/教程。这是非常基本的东西,所以你最好很好地理解这一点。祝你好运。

于 2013-07-11T13:32:32.113 回答