0

I have a code snippet which is throwing error when using printStackTrace() under catch block of my code. Following is the code snippet.

         try
     {
            # Debug Code added on 19 Feb 2016
            logger.log(Level.INFO, "baseDNs[i] = "+baseDNs[i]);
            logger.log(Level.INFO, "search ="+search);
            logger.log(Level.INFO, "attributes = "+attributes);

        it = basicCmAgent.find_managed_objects(baseDNs[i], search, attributes);
     }
     catch(Exception e)
     {
        # Debug Code added on 19 Feb 2016
        logger.log(Level.SEVERE, "Caught Error : "+e.printStackTrace());

        logger.log(Level.WARNING, "Could not find managed objects with base DN " + baseDNs[i]);
        return false;
     }

Following are the errors:

       asses/xml-apis.jar:../3pp_libraries/cxa_classes/irp3gppR99_330_j140.jar -d lib com/ericsson/nms/temip/importer/BasicCmConnection.java
    com/ericsson/nms/temip/importer/BasicCmConnection.java:177: 'void' type not allowed here
            logger.log(Level.SEVERE, "Caught Error : " +e.printStackTrace());
                                     ^
Note: ./com/ericsson/nms/temip/importer/BasicCmConverter.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
1 error
*** Error exit code 1

Stop.
*** Error exit code 1

Stop.

How can i fix this?

1
  • What's up with those negative votes guys? I understand for some people this might not be a very big issue but for a beginner like me this is still a question. Commented Feb 25, 2016 at 11:02

3 Answers 3

2

printStackTrace() has a void return type, so you can't concatenate it to a String or use it as an argument for another method.

You might want to use getStackTrace() instead.

logger.log(Level.SEVERE, "Caught Error : "+e.getStackTrace());
Sign up to request clarification or add additional context in comments.

Comments

1

e.printStackTrace() does not return a String it returns void and prints the stack trace. You are trying to do String + void = String which does not work.

Comments

0

The issue is at this line

 logger.log(Level.SEVERE, "Caught Error : "+e.printStackTrace());

The return type of e.printStackTrace is void. You cannot concat String +void.

Better use e.getStactTrace();

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.