<?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>topic Re: Catch HttpHostConnectException e in Java Maps SDK Questions</title>
    <link>https://community.esri.com/t5/java-maps-sdk-questions/catch-httphostconnectexception-e/m-p/195487#M531</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;First of all, good "catch", by the way.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;What happens when you try to catch a general Exception?&lt;/P&gt;&lt;P&gt;This is what works for me. Surround your layer definition code with a try/catch for Exception, instead of a specific one. I know it sounds improper, but this may get you farther along, hopefully?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 15 Nov 2015 18:17:01 GMT</pubDate>
    <dc:creator>EricBader</dc:creator>
    <dc:date>2015-11-15T18:17:01Z</dc:date>
    <item>
      <title>Catch HttpHostConnectException e</title>
      <link>https://community.esri.com/t5/java-maps-sdk-questions/catch-httphostconnectexception-e/m-p/195486#M530</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P style="font-size: 26px; font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;&lt;STRONG style="font-size: 10pt; font-family: verdana, geneva;"&gt;According to &lt;/STRONG&gt;&lt;A _jive_internal="true" href="https://community.esri.com/message/71839#71839" style="font-weight: inherit; font-style: inherit; font-family: inherit; color: #287433;"&gt;Not able to add ArcGISDynamicMapServiceLayer in Arc&lt;/A&gt;&lt;/P&gt;&lt;P&gt;When you don't properly set the proxy parameters you get &lt;SPAN style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif; font-weight: bold;"&gt;HttpHostConnectException. &lt;/SPAN&gt;&lt;SPAN style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif; line-height: 1.5;"&gt; How can you catch this connection exception (org.apache.http.conn.HttpHostConnectException) since it's not thrown by JMap class itself. I need to catch this error and take suitable actions or an appropriate warning message about the proxy parameters correctness.&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;I tried:&lt;/P&gt;&lt;P style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;&lt;/P&gt;&lt;P style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;MapOptions mapOptions = new MapOptions(MapType.STREETS, 24.43261, -102.92041, 4);&lt;/P&gt;&lt;P style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;try{&lt;/P&gt;&lt;P style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;JMap jMap = new JMap(mapOptions);&lt;/P&gt;&lt;P style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;&amp;nbsp; jMap.setWrapAroundEnabled(true);&lt;/P&gt;&lt;P style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;}&lt;/P&gt;&lt;P style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;catch(&lt;SPAN style="font-weight: bold; font-style: inherit;"&gt;HttpHostConnectException e&lt;/SPAN&gt;){&lt;/P&gt;&lt;P style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;&amp;nbsp;&amp;nbsp; // Handle error connection due to incorrect proxy parameters&lt;/P&gt;&lt;P style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;}&lt;/P&gt;&lt;P style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;&lt;/P&gt;&lt;P style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;But, of course, the compiler claims "Out of Reach try catch clause"&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 13 Nov 2015 18:37:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/java-maps-sdk-questions/catch-httphostconnectexception-e/m-p/195486#M530</guid>
      <dc:creator>EdgarCanul</dc:creator>
      <dc:date>2015-11-13T18:37:12Z</dc:date>
    </item>
    <item>
      <title>Re: Catch HttpHostConnectException e</title>
      <link>https://community.esri.com/t5/java-maps-sdk-questions/catch-httphostconnectexception-e/m-p/195487#M531</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;First of all, good "catch", by the way.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;What happens when you try to catch a general Exception?&lt;/P&gt;&lt;P&gt;This is what works for me. Surround your layer definition code with a try/catch for Exception, instead of a specific one. I know it sounds improper, but this may get you farther along, hopefully?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 15 Nov 2015 18:17:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/java-maps-sdk-questions/catch-httphostconnectexception-e/m-p/195487#M531</guid>
      <dc:creator>EricBader</dc:creator>
      <dc:date>2015-11-15T18:17:01Z</dc:date>
    </item>
    <item>
      <title>Re: Catch HttpHostConnectException e</title>
      <link>https://community.esri.com/t5/java-maps-sdk-questions/catch-httphostconnectexception-e/m-p/195488#M532</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Nothing happens, I used:&lt;/P&gt;&lt;P style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;&lt;/P&gt;&lt;P style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;try{&lt;/P&gt;&lt;P style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;&lt;SPAN style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; MapOptions mapOptions = new MapOptions(MapType.STREETS, 24.43261, -102.92041, 4);&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; JMap jMap = new JMap(mapOptions);&lt;/P&gt;&lt;P style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; jMap.setWrapAroundEnabled(true);&lt;/P&gt;&lt;P style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;}&lt;/P&gt;&lt;P style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;catch(&lt;SPAN style="font-weight: bold; font-style: inherit; font-family: inherit;"&gt;Exception e&lt;/SPAN&gt;){&lt;/P&gt;&lt;P style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; JOptionPane.showMessageDialog(window, "Error connection");&lt;/P&gt;&lt;P style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;}&lt;/P&gt;&lt;P style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;&lt;/P&gt;&lt;P style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;It doesn't catch it.&lt;/P&gt;&lt;P style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;&lt;/P&gt;&lt;P style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;I think the error connection occurs when creating the map because when I debug it, is in this step when the exception is thrown (after 20 seconds). But when I checked the constructor new JMap it doesn't throw any exception.&lt;/P&gt;&lt;P style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;&lt;/P&gt;&lt;P style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;Please, help.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 17 Nov 2015 15:00:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/java-maps-sdk-questions/catch-httphostconnectexception-e/m-p/195488#M532</guid>
      <dc:creator>EdgarCanul</dc:creator>
      <dc:date>2015-11-17T15:00:48Z</dc:date>
    </item>
    <item>
      <title>Re: Catch HttpHostConnectException e</title>
      <link>https://community.esri.com/t5/java-maps-sdk-questions/catch-httphostconnectexception-e/m-p/195489#M533</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You could get the exception using the getException() method on the layer. This method could be invoked after the layer has initialized.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; dynamicLayer = new ArcGISDynamicMapServiceLayer(URL_DYNAMIC_LAYER);
&amp;nbsp;&amp;nbsp;&amp;nbsp; dynamicLayer.addLayerInitializeCompleteListener(new LayerInitializeCompleteListener() {
&lt;SPAN style="line-height: 1.5;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; @Override&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; public void layerInitializeComplete(LayerInitializeCompleteEvent e) {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; System.out.println("Error: " + dynamicLayer.getException());
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&amp;nbsp;&amp;nbsp;&amp;nbsp; });&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 09:46:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/java-maps-sdk-questions/catch-httphostconnectexception-e/m-p/195489#M533</guid>
      <dc:creator>VijayGandhi</dc:creator>
      <dc:date>2021-12-11T09:46:57Z</dc:date>
    </item>
    <item>
      <title>Re: Catch HttpHostConnectException e</title>
      <link>https://community.esri.com/t5/java-maps-sdk-questions/catch-httphostconnectexception-e/m-p/195490#M534</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Sorry, could you give me more clues. I couldn't figure out how to use it. Since I don't use DynamicMapServiceLayer, according to my last snippet I tried:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&amp;nbsp; MapOptions mapOptions = new MapOptions(MapType.STREETS, 17.94262710, -95.92216487, 6);
&amp;nbsp; map = new JMap(mapOptions);
&lt;SPAN style="line-height: 1.5;"&gt;&amp;nbsp; map.getLayers().get(0).addLayerInitializeCompleteListener(new LayerInitializeCompleteListener() {&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; @Override
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; public void layerInitializeComplete(LayerInitializeCompleteEvent e) {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; System.out.println("Error: " + map.getLayers().get(0).getException().getMessage());
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; });&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Since, after creating, the map the layer[0] is the BaseMapTiled Layer. But I still can't catch the exception, I think that's because at that point the layer doesn't exist due to the connection error.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 09:47:00 GMT</pubDate>
      <guid>https://community.esri.com/t5/java-maps-sdk-questions/catch-httphostconnectexception-e/m-p/195490#M534</guid>
      <dc:creator>EdgarCanul</dc:creator>
      <dc:date>2021-12-11T09:47:00Z</dc:date>
    </item>
    <item>
      <title>Re: Catch HttpHostConnectException e</title>
      <link>https://community.esri.com/t5/java-maps-sdk-questions/catch-httphostconnectexception-e/m-p/195491#M535</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;OK Vijay. You are right. I finally could implement your suggestion. Thanks a lot. Now I'm going to try to accomodate to my app.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 17 Nov 2015 22:29:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/java-maps-sdk-questions/catch-httphostconnectexception-e/m-p/195491#M535</guid>
      <dc:creator>EdgarCanul</dc:creator>
      <dc:date>2015-11-17T22:29:12Z</dc:date>
    </item>
  </channel>
</rss>

