Question

 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();
    }

}

I'm simply trying to run this application as a java application in Eclipse-RAD using public static void main(String[] args) but it is giving me an error of:

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

on:

PGDirTestController.performExecute();

Please go easy on me, I'm pretty new to Java still.

Was it helpful?

Solution

Since you declared:

public void performExecute() throws ECException 

Then you are forced to deal with ECException.

So when you call it, you should surround it with try-catch or declare the method in which you call it to throw the exception:

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

OR

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

OTHER TIPS

First, variables should start with lowercase as per Java convention, otherwise it's confusing:

XGetProgramGuideDirectTestControllerCmdImpl pGDirTestController = new XGetProgramGuideDirectTestControllerCmdImpl();

About your question, Unhandled exception type means this method throws an exception that's not a RuntimeException and you're not handling it. In Java, you must explicitly catch all exceptions that are not children of RuntimeException.

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

The catch part will be executed whenever an ECException is thrown. You should add code here to handle what to do if this exception is thrown. I strongly advise you against leaving this catch empty, because if the exception is thrown, you'll never know.

I strongly suggest you get a Java book/tutorial if you will be working with Java. This is very basic stuff, so you better understand this very well. Good luck.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top