0
            List<String> assignedGroups = new ArrayList<>();
            assignedGroups.add("Group1");
            assignedGroups.add("Group2");
            assignedGroups.add("Group3");
            assignedGroups.add("Group4");
            assignedGroups.forEach(assignedGroup -> {

                System.out.println("");
                System.out.println("Retrieving tickets from " + assignedGroup + " ...");
                System.out.println("");

                /**
                 * @param args
                 * Cloud Server Deployment - Create server in CIA in Active state
                 */
                // Create SOAP Response
                String qualification = "'Priority' == \"Critical\" AND 'Assigned Group' = \""+ assignedGroup + "\"";
                SOAPMessage soapResponse = null;
                try {
                    soapResponse = soapConnection.call(createSOAPRequest(qualification), url);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                try {
                    if (soapResponse != null) {
                        soapResponse.writeTo(System.out);
                        System.out.println("Giant Spaghetti Monster!");
                    }
                } catch (SOAPException | IOException e) {
                    e.printStackTrace();
                }

                // Print the SOAP Response
                try {
                    printSOAPResponse(soapResponse, soapConnection);
                } catch (Exception e) {
                    e.printStackTrace();
                }

            });

Sometimes I get a NullPointerException while attempting to retrieve a SOAP response:

<?xml version="1.0" encoding="utf-8"?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><soapenv:Body><soapenv:Fault><faultcode>soapenv:Server.userException</faultcode><faultstring>ERROR (302): Entry does not exist in database; </faultstring><detail><ns1:hostname xmlns:ns1="http://xml.apache.org/axis/">WEBDKBA866</ns1:hostname></detail></soapenv:Fault></soapenv:Body></soapenv:Envelope>
java.lang.NullPointerException
    at src.RemedySOAPWebService.printSOAPResponse(RemedySOAPWebService.java:218)
    at src.RemedySOAPWebService.lambda$main$0(RemedySOAPWebService.java:78)
    at java.util.ArrayList.forEach(ArrayList.java:1249)
    at src.RemedySOAPWebService.main(RemedySOAPWebService.java:49)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)

Now, instead of fixing the exception, is there a way to ignore it and move on to the next group in the list that is being iterated over?

For example, the NPE occurs at Group3. Instead of having my script crash, can I just move to Group4? I've printed Giant Spaghetti Monster where the NPE occurs. Is this possible?

2
  • Possible duplicate of Continue a while loop after exception Commented Mar 6, 2017 at 9:34
  • Just wrap the line of code that makes the exception in a try catch block and you are good to go, but make sure you handle the situation where you might have a nullpointer or an empty array ... Commented Mar 6, 2017 at 9:34

1 Answer 1

1

You are catching SOAPException | IOException. catch the Exception too..

Sign up to request clarification or add additional context in comments.

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.