ApiException is never caught because, SAXException is thrown which can't be caught

53 views
Skip to first unread message

Padmahas Bn

unread,
Jun 15, 2017, 11:59:43 AM6/15/17
to Google's DoubleClick for Publishers API Forum
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.

Sreelakshmi Sasidharan (DFP API Team)

unread,
Jun 15, 2017, 3:31:49 PM6/15/17
to Google's DoubleClick for Publishers API Forum
Hi Padmahas, 

Could you please update your Java client library and try running your code again? There was an issue with the library version : 3.0.0. Upgrading the version to the next higher version (deprecated) or latest should hopefully fix the problem. Please give it a try and let me know how it goes. 

Thanks,
Sreelakshmi Sasidharan, DFP API Team

Padmahas Bn

unread,
Jun 16, 2017, 9:53:28 AM6/16/17
to Google's DoubleClick for Publishers API Forum
Hello SreeLakshme,

Thank you for suggesting upgrading Library version. I upgraded to 3.4.0
It worked perfectly to me. ApiException caught successfully.

Thank you again.

Sreelakshmi Sasidharan (DFP API Team)

unread,
Jun 16, 2017, 10:25:57 AM6/16/17
to Google's DoubleClick for Publishers API Forum
Hi Padmahas, 

Glad to know that the library version upgrade fixed the issue.
Reply all
Reply to author
Forward
0 new messages