<?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: Can't catch RuntimeException on ArcGISRuntime.initialize() in Java Maps SDK Questions</title>
    <link>https://community.esri.com/t5/java-maps-sdk-questions/can-t-catch-runtimeexception-on-arcgisruntime/m-p/392966#M1205</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Could somebody explain to me why I &lt;STRONG&gt;can't catch the RuntimeException when initializing an ArcGIS Runtime Licence&lt;/STRONG&gt;?&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm not certain you can catch them in the same way you can't catch OS-level exceptions in .NET apps (at least not nicely). Consider this &lt;/SPAN&gt;&lt;A href="http://docs.oracle.com/javase/tutorial/essential/exceptions/runtime.html"&gt;reading&lt;/A&gt;&lt;SPAN&gt; which has a point of observation:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Here's the bottom line guideline: If a client can reasonably be expected to recover from an exception, make it a checked exception. If a client cannot do anything to recover from the exception, make it an unchecked exception.&lt;/BLOCKQUOTE&gt;&lt;SPAN&gt;&amp;nbsp; I can't say that I blame the API for protecting itself in the manner in which it's behaving.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;I'm using following code, which fire a RuntimeException on ArcGISRuntime.initialize(), but it's not catched, and only way to know that Licence is not valid, is by checking with ArcGISRuntime.isLicensed()&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Not entirely true; there is an &lt;/SPAN&gt;&lt;A href="http://resources.arcgis.com/en/help/runtime-java/apiref/com/esri/client/local/LicenseStatus.html"&gt;LicenseStatus&lt;/A&gt;&lt;SPAN&gt; enumeration that can be used to compare against ArcGISRuntime's &lt;/SPAN&gt;&lt;A href="http://resources.arcgis.com/en/help/runtime-java/apiref/com/esri/runtime/ArcGISRuntime.html#getLicenseStatus()"&gt;getLicense()&lt;/A&gt;&lt;SPAN&gt; method.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;in Debug, the code line "&lt;STRONG&gt;ArcGISRuntime.initialize();&lt;/STRONG&gt;" fire following exception in my Console, but program continu on line "&lt;STRONG&gt;return true;&lt;/STRONG&gt;".&lt;BR /&gt;Finally "&lt;STRONG&gt;ArcGISRuntime.isLicensed()&lt;/STRONG&gt;" return "&lt;STRONG&gt;false&lt;/STRONG&gt;", but I would prefer to catch the RuntimeException in order to get the error message ! ... Any ideas ?&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;In my experience, I noticed that most licensing exceptions occur when the "main" license is not properly set (as in the first to be set before other extensions). This is probably why there is a &lt;/SPAN&gt;&lt;A href="http://resources.arcgis.com/en/help/runtime-java/apiref/com/esri/runtime/ArcGISRuntime.html#setLicense(java.lang.String,%20java.lang.String...)"&gt;method &lt;/A&gt;&lt;SPAN&gt;that takes these licenses in separate parameters. Most ArcGIS Runtime Template applications ESRI has posted, such as &lt;/SPAN&gt;&lt;A href="http://www.google.ca/url?sa=t&amp;amp;rct=j&amp;amp;q=vehicle%20commander%20template&amp;amp;source=web&amp;amp;cd=1&amp;amp;cad=rja&amp;amp;ved=0CDcQFjAA&amp;amp;url=http%3A%2F%2Fwww.arcgis.com%2Fhome%2Fitem.html%3Fid%3Dae30551d12f443cb903f4829b03de315&amp;amp;ei=J5iGUZPfCuL9igKoqIHgBA&amp;amp;usg=AFQjCNFFWtpglmUZPz7atY_I9wIjo4ArkQ"&gt;Vehicle Commander&lt;/A&gt;&lt;SPAN&gt; which demonstrate "best practices for building ... applications with ArcGIS", has code for how to handle application licensing.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;You could also use the aforementioned LicenseStatus enumeration and the getLicenseStatus() method along with the methods &lt;/SPAN&gt;&lt;A href="http://resources.arcgis.com/en/help/runtime-java/apiref/com/esri/runtime/ArcGISRuntime.html#getLicenseBytes()"&gt;getLicenseBytes() &lt;/A&gt;&lt;SPAN&gt;and &lt;/SPAN&gt;&lt;A href="http://resources.arcgis.com/en/help/runtime-java/apiref/com/esri/runtime/ArcGISRuntime.html#getLicenseExtensions()"&gt;getLicenseExtensions()&lt;/A&gt;&lt;SPAN&gt;, which gives you the byte[]'s set, to build your own specific error message.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Hope this helps.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 05 May 2013 16:41:41 GMT</pubDate>
    <dc:creator>CarlosColón-Maldonado</dc:creator>
    <dc:date>2013-05-05T16:41:41Z</dc:date>
    <item>
      <title>Can't catch RuntimeException on ArcGISRuntime.initialize()</title>
      <link>https://community.esri.com/t5/java-maps-sdk-questions/can-t-catch-runtimeexception-on-arcgisruntime/m-p/392965#M1204</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Could somebody explain to me why I &lt;/SPAN&gt;&lt;STRONG&gt;can't catch the RuntimeException when initializing an ArcGIS Runtime Licence&lt;/STRONG&gt;&lt;SPAN&gt; ?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm using following code, which fire a RuntimeException on ArcGISRuntime.initialize(), but it's not catched, and only way to know that Licence is not valid, is by checking with ArcGISRuntime.isLicensed() :&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;public class Main{
&amp;nbsp;&amp;nbsp;&amp;nbsp; public static void main(String[] args)throws Exception {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (initializeLicenceArcGIS()) {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (ArcGISRuntime.isLicensed()) {
&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; InitializeApplication.main(args);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; -&amp;gt; end up here !!
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; JOptionPane.showMessageDialog(null, "ArcGIS Licence is not initialized !", "Initialize Application", JOptionPane.ERROR_MESSAGE);
&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; private static boolean initializeLicenceArcGIS() {
 try
 {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ArcGISRuntime.setLicense("No Licence Available");
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ArcGISRuntime.initialize();&amp;nbsp; (-&amp;gt; see Console out print below)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return true;&amp;nbsp;&amp;nbsp; (-&amp;gt; continu here and return true with invalid licence)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
 } catch (RuntimeException e) {
&amp;nbsp; -&amp;gt; never catch here ??
&amp;nbsp; JOptionPane.showMessageDialog(null, "Error when licencing ArcGIS: " + e.getMessage(), "Initialize Application", JOptionPane.ERROR_MESSAGE); 
&amp;nbsp; return false;
 } catch (Exception e) {
&amp;nbsp; JOptionPane.showMessageDialog(null, "Error when licencing ArcGIS: " + e.getMessage(), "Initialize Application", JOptionPane.ERROR_MESSAGE); 
&amp;nbsp; return false;
 }
&amp;nbsp;&amp;nbsp;&amp;nbsp; }
}&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;in Debug, the code line "&lt;/SPAN&gt;&lt;STRONG&gt;ArcGISRuntime.initialize();&lt;/STRONG&gt;&lt;SPAN&gt;" fire following exception in my Console, but program continu on line "&lt;/SPAN&gt;&lt;STRONG&gt;return true;&lt;/STRONG&gt;&lt;SPAN&gt;".&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Finally "&lt;/SPAN&gt;&lt;STRONG&gt;ArcGISRuntime.isLicensed()&lt;/STRONG&gt;&lt;SPAN&gt;" return "&lt;/SPAN&gt;&lt;STRONG&gt;false&lt;/STRONG&gt;&lt;SPAN&gt;", but I would prefer to catch the RuntimeException in order to get the error message !&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;java.lang.RuntimeException: License error with ArcGISRuntime. Main license is invalid.
 at com.esri.runtime.ArcGISRuntime.nativeInitLicenses(Native Method)
 at com.esri.runtime.ArcGISRuntime.e(Unknown Source)
 at com.esri.runtime.ArcGISRuntime.initialize(Unknown Source)
 at com.example.forum.initialize.Main.initializeLicenceArcGIS(Main.java:24)
 at com.example.forum.initialize.Main.main(Main.java:9)&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Any ideas ?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 16:25:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/java-maps-sdk-questions/can-t-catch-runtimeexception-on-arcgisruntime/m-p/392965#M1204</guid>
      <dc:creator>JeremieJoalland1</dc:creator>
      <dc:date>2021-12-12T16:25:20Z</dc:date>
    </item>
    <item>
      <title>Re: Can't catch RuntimeException on ArcGISRuntime.initialize()</title>
      <link>https://community.esri.com/t5/java-maps-sdk-questions/can-t-catch-runtimeexception-on-arcgisruntime/m-p/392966#M1205</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Could somebody explain to me why I &lt;STRONG&gt;can't catch the RuntimeException when initializing an ArcGIS Runtime Licence&lt;/STRONG&gt;?&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm not certain you can catch them in the same way you can't catch OS-level exceptions in .NET apps (at least not nicely). Consider this &lt;/SPAN&gt;&lt;A href="http://docs.oracle.com/javase/tutorial/essential/exceptions/runtime.html"&gt;reading&lt;/A&gt;&lt;SPAN&gt; which has a point of observation:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Here's the bottom line guideline: If a client can reasonably be expected to recover from an exception, make it a checked exception. If a client cannot do anything to recover from the exception, make it an unchecked exception.&lt;/BLOCKQUOTE&gt;&lt;SPAN&gt;&amp;nbsp; I can't say that I blame the API for protecting itself in the manner in which it's behaving.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;I'm using following code, which fire a RuntimeException on ArcGISRuntime.initialize(), but it's not catched, and only way to know that Licence is not valid, is by checking with ArcGISRuntime.isLicensed()&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Not entirely true; there is an &lt;/SPAN&gt;&lt;A href="http://resources.arcgis.com/en/help/runtime-java/apiref/com/esri/client/local/LicenseStatus.html"&gt;LicenseStatus&lt;/A&gt;&lt;SPAN&gt; enumeration that can be used to compare against ArcGISRuntime's &lt;/SPAN&gt;&lt;A href="http://resources.arcgis.com/en/help/runtime-java/apiref/com/esri/runtime/ArcGISRuntime.html#getLicenseStatus()"&gt;getLicense()&lt;/A&gt;&lt;SPAN&gt; method.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;in Debug, the code line "&lt;STRONG&gt;ArcGISRuntime.initialize();&lt;/STRONG&gt;" fire following exception in my Console, but program continu on line "&lt;STRONG&gt;return true;&lt;/STRONG&gt;".&lt;BR /&gt;Finally "&lt;STRONG&gt;ArcGISRuntime.isLicensed()&lt;/STRONG&gt;" return "&lt;STRONG&gt;false&lt;/STRONG&gt;", but I would prefer to catch the RuntimeException in order to get the error message ! ... Any ideas ?&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;In my experience, I noticed that most licensing exceptions occur when the "main" license is not properly set (as in the first to be set before other extensions). This is probably why there is a &lt;/SPAN&gt;&lt;A href="http://resources.arcgis.com/en/help/runtime-java/apiref/com/esri/runtime/ArcGISRuntime.html#setLicense(java.lang.String,%20java.lang.String...)"&gt;method &lt;/A&gt;&lt;SPAN&gt;that takes these licenses in separate parameters. Most ArcGIS Runtime Template applications ESRI has posted, such as &lt;/SPAN&gt;&lt;A href="http://www.google.ca/url?sa=t&amp;amp;rct=j&amp;amp;q=vehicle%20commander%20template&amp;amp;source=web&amp;amp;cd=1&amp;amp;cad=rja&amp;amp;ved=0CDcQFjAA&amp;amp;url=http%3A%2F%2Fwww.arcgis.com%2Fhome%2Fitem.html%3Fid%3Dae30551d12f443cb903f4829b03de315&amp;amp;ei=J5iGUZPfCuL9igKoqIHgBA&amp;amp;usg=AFQjCNFFWtpglmUZPz7atY_I9wIjo4ArkQ"&gt;Vehicle Commander&lt;/A&gt;&lt;SPAN&gt; which demonstrate "best practices for building ... applications with ArcGIS", has code for how to handle application licensing.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;You could also use the aforementioned LicenseStatus enumeration and the getLicenseStatus() method along with the methods &lt;/SPAN&gt;&lt;A href="http://resources.arcgis.com/en/help/runtime-java/apiref/com/esri/runtime/ArcGISRuntime.html#getLicenseBytes()"&gt;getLicenseBytes() &lt;/A&gt;&lt;SPAN&gt;and &lt;/SPAN&gt;&lt;A href="http://resources.arcgis.com/en/help/runtime-java/apiref/com/esri/runtime/ArcGISRuntime.html#getLicenseExtensions()"&gt;getLicenseExtensions()&lt;/A&gt;&lt;SPAN&gt;, which gives you the byte[]'s set, to build your own specific error message.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Hope this helps.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 05 May 2013 16:41:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/java-maps-sdk-questions/can-t-catch-runtimeexception-on-arcgisruntime/m-p/392966#M1205</guid>
      <dc:creator>CarlosColón-Maldonado</dc:creator>
      <dc:date>2013-05-05T16:41:41Z</dc:date>
    </item>
  </channel>
</rss>

