gpt4 book ai didi

java - 异常后继续列表迭代

转载 作者:行者123 更新时间:2023-12-01 08:46:35 25 4
gpt4 key购买 nike

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

});

有时,我在尝试检索 SOAP 响应时会收到 NullPointerException:

<?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)

现在,有没有办法忽略它并继续迭代列表中的下一组,而不是修复异常?

例如,NPE 发生在 Group3。我可以直接转到 Group4 来避免脚本崩溃吗?我已经在 NPE 发生的地方打印了 Giant Spaghetti Monster。这可能吗?

最佳答案

您正在捕获 SOAPException | IOException。也捕获异常..

关于java - 异常后继续列表迭代,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42621824/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com