<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>Question Re: Exception handling in a Web Client function? in Technology Q&amp;A</title>
    <link>https://community.sap.com/t5/technology-q-a/exception-handling-in-a-web-client-function/qaa-p/13821693#M4852536</link>
    <description>&lt;P&gt;Thank you Breck and Volker, that's just the answer I needed!&lt;/P&gt;</description>
    <pubDate>Thu, 11 Jun 2020 16:48:16 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2020-06-11T16:48:16Z</dc:date>
    <item>
      <title>Exception handling in a Web Client function?</title>
      <link>https://community.sap.com/t5/technology-q-a/exception-handling-in-a-web-client-function/qaq-p/13821688</link>
      <description>&lt;P&gt;I would be grateful for some pointers:&lt;/P&gt;
&lt;P&gt;I am trying to use the Web Service feature of SQL Anywhere 16.0.0.2076 to POST to a URL, however I am finding that often, even though the URL is correct, I get an error that states that it cannot connect to the URL.  I know the URL is correct as if I try again, it works correctly. What I would like to be able to do is either handle the error and automatically retry, or find a way to use Exception Handling to do it myself.&lt;/P&gt;
&lt;P&gt;If I set up a function with an invalid URL to deliberately generate the same error, such as:&lt;/P&gt;
&lt;PRE&gt;CREATE FUNCTION "spaceman"."WebServiceTest"(in "iData" long varchar) 
returns xml
url 'http://www.mynonexistentwebservice.com'
type 'HTTP:POST:text/xml'
&lt;/PRE&gt;

&lt;P&gt;and then &lt;/P&gt;&lt;PRE&gt;select WebServiceTest('Hello')&lt;/PRE&gt; I get:
&lt;PRE&gt;Unable to connect to the remote host specified by
'http://www.mynonexistentwebservice.com'
SQLCODE=-981, ODBC 3 State="HY000"&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;
&lt;P&gt;How can I handle this error myself?  I cannot put exception handling in the original function, and if I call this function with another procedure that contains the exception handling, it is ignored - I assume as it is not this second procedure that is causing the issue:&lt;/P&gt;
&lt;PRE&gt;Create procedure mysecondproc()
begin
select WebServiceTest('Hello');
    exception
    when others then
    message(string(SQLCODE,'  - ',SQLState))
END&lt;/PRE&gt;

&lt;P&gt;Many thanks indeed&lt;/P&gt;
&lt;P&gt;Rip&lt;/P&gt;</description>
      <pubDate>Thu, 11 Jun 2020 13:45:44 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/exception-handling-in-a-web-client-function/qaq-p/13821688</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2020-06-11T13:45:44Z</dc:date>
    </item>
    <item>
      <title>Re: Exception handling in a Web Client function?</title>
      <link>https://community.sap.com/t5/technology-q-a/exception-handling-in-a-web-client-function/qaa-p/13821689#M4852532</link>
      <description>&lt;P&gt;You are right, you cannot add exception handling to the web client function as it has no body. So exception handling must be done within the wrapper function/procedure. I guess this does not work as expected in your sample as the procedure just returns the result to the caller, and the error just appears during the opening of the result set. Try to consume the result set within the procedure itself (say, by using a local variable of type xml to store the function's return value, and then selecting the local variable as result set. Then the exception should by caught within the procedure itself.&lt;/P&gt;
&lt;P&gt;FWIW, you might try Web client logging to find out why the web request does fail sometimes.&lt;/P&gt;</description>
      <pubDate>Thu, 11 Jun 2020 14:34:25 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/exception-handling-in-a-web-client-function/qaa-p/13821689#M4852532</guid>
      <dc:creator>VolkerBarth</dc:creator>
      <dc:date>2020-06-11T14:34:25Z</dc:date>
    </item>
    <item>
      <title>Re: Exception handling in a Web Client function?</title>
      <link>https://community.sap.com/t5/technology-q-a/exception-handling-in-a-web-client-function/qaa-p/13821690#M4852533</link>
      <description>&lt;P&gt;The problem is that the "select WebServiceTest('Hello');" effectively returns from the procedure immediately, without executing any code that follows.&lt;/P&gt;
&lt;P&gt;The solution is to use SET local (or SELECT INTO local) to call the function, then SELECT local to return the successful value... an error in the SET local or SELECT INTO local will be captureed.&lt;/P&gt;
&lt;P&gt;I had to code this kludge in many locations throughout Foxhound.&lt;/P&gt;
&lt;PRE&gt;Create procedure mysecondproc2()
begin
declare x XML;
SET x = WebServiceTest('Hello');
SELECT x;
    exception
    when others then
    message(string(SQLCODE,'  - ',SQLState))
END;

CALL mysecondproc2();

-981  - WW050
&lt;/PRE&gt;</description>
      <pubDate>Thu, 11 Jun 2020 14:45:49 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/exception-handling-in-a-web-client-function/qaa-p/13821690#M4852533</guid>
      <dc:creator>Breck_Carter</dc:creator>
      <dc:date>2020-06-11T14:45:49Z</dc:date>
    </item>
    <item>
      <title>Re: Exception handling in a Web Client function?</title>
      <link>https://community.sap.com/t5/technology-q-a/exception-handling-in-a-web-client-function/qaa-p/13821691#M4852534</link>
      <description>&lt;P&gt;In other words, what Volker said &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&lt;IMG width="150" src="https://i.imgflip.com/3e66cv.jpg" /&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 11 Jun 2020 14:47:14 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/exception-handling-in-a-web-client-function/qaa-p/13821691#M4852534</guid>
      <dc:creator>Breck_Carter</dc:creator>
      <dc:date>2020-06-11T14:47:14Z</dc:date>
    </item>
    <item>
      <title>Re: Exception handling in a Web Client function?</title>
      <link>https://community.sap.com/t5/technology-q-a/exception-handling-in-a-web-client-function/qaa-p/13821692#M4852535</link>
      <description>&lt;P&gt;Just to add: Here's an explanation &lt;A href="https://sqlanywhere-forum.sap.com/questions/1612/what-happens-when-a-procedure-result-set-is-ignored"&gt;why SQL Anywhere handles result sets in procedures&lt;/A&gt; that way, quite different from other database products...&lt;/P&gt;</description>
      <pubDate>Thu, 11 Jun 2020 15:05:27 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/exception-handling-in-a-web-client-function/qaa-p/13821692#M4852535</guid>
      <dc:creator>VolkerBarth</dc:creator>
      <dc:date>2020-06-11T15:05:27Z</dc:date>
    </item>
    <item>
      <title>Re: Exception handling in a Web Client function?</title>
      <link>https://community.sap.com/t5/technology-q-a/exception-handling-in-a-web-client-function/qaa-p/13821693#M4852536</link>
      <description>&lt;P&gt;Thank you Breck and Volker, that's just the answer I needed!&lt;/P&gt;</description>
      <pubDate>Thu, 11 Jun 2020 16:48:16 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/exception-handling-in-a-web-client-function/qaa-p/13821693#M4852536</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2020-06-11T16:48:16Z</dc:date>
    </item>
  </channel>
</rss>

