Select to view content in your preferred language

Can't catch RuntimeException on ArcGISRuntime.initialize()

3404
1
05-03-2013 12:24 AM
JeremieJoalland1
Deactivated User
Could somebody explain to me why I can't catch the RuntimeException when initializing an ArcGIS Runtime Licence ?

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() :

public class Main{
    public static void main(String[] args)throws Exception {
     if (initializeLicenceArcGIS()) {
      if (ArcGISRuntime.isLicensed()) {
              InitializeApplication.main(args);
      }
      else {
       -> end up here !!
       JOptionPane.showMessageDialog(null, "ArcGIS Licence is not initialized !", "Initialize Application", JOptionPane.ERROR_MESSAGE);
      }
     }
    }
    
    private static boolean initializeLicenceArcGIS() {
 try
 {
     ArcGISRuntime.setLicense("No Licence Available");
     ArcGISRuntime.initialize();  (-> see Console out print below)
     return true;   (-> continu here and return true with invalid licence)
     
 } catch (RuntimeException e) {
  -> never catch here ??
  JOptionPane.showMessageDialog(null, "Error when licencing ArcGIS: " + e.getMessage(), "Initialize Application", JOptionPane.ERROR_MESSAGE); 
  return false;
 } catch (Exception e) {
  JOptionPane.showMessageDialog(null, "Error when licencing ArcGIS: " + e.getMessage(), "Initialize Application", JOptionPane.ERROR_MESSAGE); 
  return false;
 }
    }
}


in Debug, the code line "ArcGISRuntime.initialize();" fire following exception in my Console, but program continu on line "return true;".
Finally "ArcGISRuntime.isLicensed()" return "false", but I would prefer to catch the RuntimeException in order to get the error message !

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)


Any ideas ?
0 Kudos
1 Reply
CarlosColón-Maldonado
Frequent Contributor
Could somebody explain to me why I can't catch the RuntimeException when initializing an ArcGIS Runtime Licence?


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 reading which has a point of observation:
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.
  I can't say that I blame the API for protecting itself in the manner in which it's behaving.

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()


Not entirely true; there is an LicenseStatus enumeration that can be used to compare against ArcGISRuntime's getLicense() method.

in Debug, the code line "ArcGISRuntime.initialize();" fire following exception in my Console, but program continu on line "return true;".
Finally "ArcGISRuntime.isLicensed()" return "false", but I would prefer to catch the RuntimeException in order to get the error message ! ... Any ideas ?


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 method that takes these licenses in separate parameters. Most ArcGIS Runtime Template applications ESRI has posted, such as Vehicle Commander which demonstrate "best practices for building ... applications with ArcGIS", has code for how to handle application licensing.

You could also use the aforementioned LicenseStatus enumeration and the getLicenseStatus() method along with the methods getLicenseBytes() and getLicenseExtensions(), which gives you the byte[]'s set, to build your own specific error message.

Hope this helps.
0 Kudos