Hello,
I was following
this blog to catch ApiException. So I intentionally gave invalid input by commenting out costPerUnit for LineItemService.
// Set the cost per unit to $2.
lineItem.setCostType(CostType.CPM);
// lineItem.setCostPerUnit(new Money("USD", 20000L));
But this is not throwing any ApiException, instead, its throwing SAXException. So I tried catching SAXException but its giving out compilation error "Unreachable catch block, SAXException is never thrown.....".
Hence I just caught general "Exception" and found that its throwing "NullPOinterException". So from my observation and the suggestion from SreeLaskmi at the 10th reply of
this thread, I implemented "NullPinterException" catch block, but even that was also not caught.
Below is the SOAP request and the Exception.
[15 Jun 2017 21:06:12,283-requestInfoLogger:INFO:main] Request made: Service: "LineItemServiceInterfacePort" Method: "createLineItems" URL: "https://ads.google.com/apis/ads/publisher/v201702/LineItemService" Request ID: "null"
[Fatal Error] :1:1: Content is not allowed in prolog.
ERROR: 'Content is not allowed in prolog.'
[15 Jun 2017 21:06:12,431-soapXmlLogger:WARN:main] SOAP Request:
<?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:Header>
<ns1:RequestHeader xmlns:ns1="https://www.google.com/apis/ads/publisher/v201702" soapenv:mustUnderstand="0">
<ns1:networkCode>5910</ns1:networkCode>
<ns1:applicationName>caapp2 (DfpApi-Java, Dfp-Axis/3.0.0, Common-Java/3.0.0, Axis/1.4, Java/1.8.0_102, maven)</ns1:applicationName>
</ns1:RequestHeader>
</soapenv:Header>
<soapenv:Body>
<createLineItems xmlns="https://www.google.com/apis/ads/publisher/v201702">
<lineItems>
<orderId>547945036</orderId>
<name>WithoutError326121974</name>
<startDateTimeType>IMMEDIATELY</startDateTimeType>
<endDateTime>
<date>
<year>2017</year>
<month>7</month>
<day>15</day>
</date>
<hour>19</hour>
<minute>35</minute>
<second>22</second>
<timeZoneID>Asia/Dubai</timeZoneID>
</endDateTime>
<creativeRotationType>EVEN</creativeRotationType>
<lineItemType>ADSENSE</lineItemType>
<priority>4</priority>
<costType>CPM</costType>
<creativePlaceholders>
<size>
<width>300</width>
<height>250</height>
<isAspectRatio>false</isAspectRatio>
</size>
</creativePlaceholders>
<allowOverbook>true</allowOverbook>
<webPropertyCode>ca-pub-415070496312123</webPropertyCode>
<primaryGoal>
<goalType>DAILY</goalType>
<unitType>IMPRESSIONS</unitType>
<units>58</units>
</primaryGoal>
<targeting>
<geoTargeting>
<targetedLocations>
<id>2356</id>
</targetedLocations>
<targetedLocations>
<id>20461</id>
</targetedLocations>
<targetedLocations>
<id>9000093</id>
</targetedLocations>
<excludedLocations>
<id>1016367</id>
</excludedLocations>
<excludedLocations>
<id>200501</id>
</excludedLocations>
</geoTargeting>
<inventoryTargeting>
<targetedAdUnits>
<adUnitId>5889796</adUnitId>
<includeDescendants>true</includeDescendants>
</targetedAdUnits>
</inventoryTargeting>
</targeting>
</lineItems>
</createLineItems>
</soapenv:Body>
</soapenv:Envelope>
[15 Jun 2017 21:06:12,432-soapXmlLogger:WARN:main] SOAP Response:
velope>
Exception caught. org.xml.sax.SAXException: Invalid element in com.google.api.ads.dfp.axis.v201702.NotNullError - fieldPathElements
Exception in thread "main" java.lang.NullPointerException
at dfp.axis.v201702.lineitemservice.CreateLineItemsExceptionHandling.runExample(CreateLineItemsExceptionHandling.java:266)
at dfp.axis.v201702.lineitemservice.CreateLineItemsExceptionHandling.main(CreateLineItemsExceptionHandling.java:289)Why its not caught by ApiException in the first place. And why can't the specific "NullPointerException" also was not caught?
The hierarchy of Exception is,
ApiException
NullPointerException
Exception.
Thank you.